php获取系统常量
PHP提供的系统常量可以让你得到当前的行号 (__LINE__),文件 (__FILE__),目录 (__DIR__),函数名 (__FUNCTION__),类名(__CLASS__
天晟网 小编在整理编程教程 > PHP > 看到php获取系统常量 ,下面是小编45为您找到的37943相关内容,希望45对您有帮助。
PHP提供的系统常量可以让你得到当前的行号 (__LINE__),文件 (__FILE__),目录 (__DIR__),函数名 (__FUNCTION__),类名(__CLASS__),方法名(__METHOD__) 和名字空间 (__NAMESPACE__)我们可以以为这些东西主要是用于调试,当然也不一定,比如我们可以在include其它文件的时候使用__FILE__ (当然,你也可以在 PHP 5.3以后使用 __DIR__ ),看如下示例:
<?php
// this is relative to the loaded script's path
// it may cause problems when running scripts from different directories
require_once('config/database.php');
// this is always relative to this file's path
// no matter where it was included from
require_once(dirname(__FILE__) . '/config/database.php');
?>
如下示例是使用 __LINE__ 来输出一些debug的信息,这样有助于你调试程序:
<?php
// some code
// …
my_debug("some debug message", __LINE__);
/* 输出
Line 4: some debug message
*/
// some more code
// …
my_debug("another debug message", __LINE__);
/* 输出
Line 11: another debug message
*/
function my_debug($msg, $line) {
echo "Line $line: $msgn";
}
?>
转载文章请标明来自天晟网 - Timsion.com > 编程教程 > PHP >
标题:php获取系统常量
网址:http://www.timsion.com/php/37943.html
上一篇:php获取CPU使用情况信息
下一篇:php生成唯一的id
免责声明:以上内容来自互联网和用户投稿,不代表本站的观点和立场,版权归原作者所有,如有侵权,请与我们联系。