不常用但很实用的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基于mcrypt_encrypt和mcrypt_decrypt实现字符串加密解密的方法

本文实例讲述了php基于mcrypt_encrypt和mcrypt_decrypt实现字符串加密解密的方法。分享给大家供大家参考,具体如下: 由于出于安全考虑,参数传递的时候需要进行加密...

深入file_get_contents与curl函数的详解

有些主机服务商把php的allow_url_fopen选项是关闭了,就是没法直接使用file_get_contents来获取远程web页面的内容。那就是可以使用另外一个函数curl。下面...

基于PHP遍历数组的方法汇总分析

1. foreach()foreach()是一个用来遍历数组中数据的最简单有效的方法。#example1:复制代码 代码如下:<?php$colors= array('red','...

php getimagesize 上传图片的长度和宽度检测代码

getimagesize — 取得图像大小 说明 array getimagesize ( string $filename [, array &$imageinfo ] ) getim...

PHP简单字符串过滤方法示例

PHP简单字符串过滤方法示例

本文实例讲述了PHP简单字符串过滤方法。分享给大家供大家参考,具体如下: <!DOCTYPE html> <html lang="zh-cn"> <he...