魔术方法__repr__
Setting constants in PHP is as easy as using the define function, but PHP creates a few constants in every script for you that help mostly for debugging purposes (well, that's generally the only time I use them). These constants are called "magic constants."
在PHP中设置常量与使用define函数一样容易,但是PHP在每个脚本中都会为您创建一些常量,这些常量主要用于调试目的(嗯,通常这是我唯一的一次使用) 。 这些常数称为“魔术常数”。
Magic constants have a funny syntax, placing two underscores before and after the constant's word representation. These are PHP's magic constants:
魔术常量的语法很有趣,在常量的单词表示形式之前和之后都有两个下划线。 这些是PHP的魔术常数:
__LINE__
__FILE__
__FUNCTION__
__CLASS__
__METHOD__
You can imagine how helpful these constants are for debugging...but if you can't:
您可以想象这些常量对调试有多大帮助...但是,如果您不能这样做:
if($sugar == '') { echo('$sugar has no value on line '.__LINE__.' of ['.__FILE__.']'); }
There are also helpful uses for these magic constants:
这些魔术常数也有一些有用的用途:
dirname(__FILE__) // get the directory name of the current script
What do you use them for?
你用它们做什么?
魔术方法__repr__