不常用但很实用的PHP预定义变量分析

yipeiwu_com6年前PHP代码库

1. $php_errormsg — 前一个错误信息

<?php

@strpos();

echo $php_errormsg;

?>

2.$http_response_header — HTTP 响应头

<?php

function get_contents() {

 file_get_contents("http://example.com");

 var_dump($http_response_header);

}

get_contents();

var_dump($http_response_header);

?>

3. $argc — 传递给脚本的参数数目

<?php

var_dump($argc);

?>

当使用这个命令执行: php script.php arg1 arg2 arg3

4. $argv — 传递给脚本的参数数组

<?php

var_dump($argv);

?>

当使用这个命令执行:php script.php arg1 arg2 arg3
  • __FILE__:返回所在路径文件名和文件名称
  • __DIR__:返回文件所在的完整目录
  • __LINE__:返回当前文件代码的行号
  • __CLASS__:返回当前类名
  • __FUNCTION__:返回当前方法名
  • __METHOD__:返回当前类名和方法名
var_dump(__FILE__); //所在路径文件名和文件名称   E:\demo\blog_code\predefined\predefined.php
var_dump(__DIR__); //所在完整目录         E:\demo\blog_code\predefined
var_dump(__LINE__); //代码所在行号         4
class testClass{
  function testMethod(){
    var_dump(__FUNCTION__); //返回当前方法名  testMethod
    var_dump(__CLASS__);  //返回类名     testClass
    var_dump(__METHOD__);  //类名加方法名   testClass::testMethod
  }
}
 
$a=new testClass();
$a->testMethod();

相关文章

php引用计数器进行垃圾收集机制介绍

PHP 有一个非常简单的垃圾收集器,它实际上将对不再位于内存范围(scope)中的对象进行垃圾收集。垃圾收集的内部方式是使用一个引用计数器,因此当计数器达到 0 时(意味着对该对象的引用...

php中常见的sql攻击正则表达式汇总

本文实例讲述了php中常见的sql攻击正则表达式。分享给大家供大家参考。具体分析如下: 我们都已经知道,在MYSQL 5+中 information_schema库中存储了所有的 库名,...

如何用C语言编写PHP扩展的详解

如何用C语言编写PHP扩展的详解

1:预定义在home目录,也可以其他任意目录,写一个文件,例如caleng_module.def内容是你希望定义的函数名以及参数:int a(int x,int y)string b(s...

基于php split()函数的用法详解

PHP函数split()的基本语法为:array split ( string $pattern, string $string [, int $limit] )。我们向大家举了两个例子...

thinkphp中U方法按路由规则生成url的方法

如下所示: //更改模块配置文件 'URL_ROUTER_ON' => true, 'URL_ROUTE_RULES'=>[]//编写路由优化 tp开启路由后,使...