php魔,php魔术常量

PHP 提供了获取当前行号 (__LINE__)、文件路径 (__FILE__)、目录路径 (__DIR__)、函数名 (__FUNCTION__)、类名 (__CLASS__)、方法名 (__METHOD__) 和命名空间 (__NAMESPACE__) 等有用的魔术常量。在这篇文章中不作一一介绍,但是我将告诉你一些用例。当包含其他脚本文件时,使用 __FILE__ 常量(或者使用 PHP5.3 新具有的 __DIR__ 常量):

复制代码 代码如下:

// 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__ 使得调试更为轻松。你可以跟踪到具体行号。

复制代码 代码如下:

// some code

// ...

my_debug("some debug message", __LINE__);

/* prints

Line 4: some debug message

*/

// some more code

// ...

my_debug("another debug message", __LINE__);

/* prints

Line 11: another debug message

*/

function my_debug($msg, $line) {

echo "Line $line: $msg\n";

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值