PHP中哪些不常用但非常实用的预定义变量有哪些?

2026-04-02 05:311阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计324个文字,预计阅读时间需要2分钟。

PHP中哪些不常用但非常实用的预定义变量有哪些?

1. `$php_errormsg` — 显示上一个错误信息,使用 `strpos()` 函数定位。

2.`$http_response_header` — 获取HTTP响应头,使用 `file_get_contents()` 函数从指定URL获取内容。

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

<?php @strpos(); echo $php_errormsg; ?>

2.$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中哪些不常用但非常实用的预定义变量有哪些?

本文共计324个文字,预计阅读时间需要2分钟。

PHP中哪些不常用但非常实用的预定义变量有哪些?

1. `$php_errormsg` — 显示上一个错误信息,使用 `strpos()` 函数定位。

2.`$http_response_header` — 获取HTTP响应头,使用 `file_get_contents()` 函数从指定URL获取内容。

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

<?php @strpos(); echo $php_errormsg; ?>

2.$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中哪些不常用但非常实用的预定义变量有哪些?