Home >Backend Development >PHP Tutorial >Detailed explanation and examples of php magic constants
Magic constants PHP provides a large number of predefined constants to any script it runs. Our commonly used PHP magic constants are __CLASS__ __FUNCTION__ __LINE__ __FILE__ __DIR__ __METHOD__. This article introduces PHP magic constants to you through PHP examples
php Detailed explanation of magic constants
Example:
class MoShu{ public function moshu() { echo '当前类名:' . __CLASS__ . "<br />"; echo '当前方法名:' . __FUNCTION__ . "<br />"; echo '当前文件中所在的行数:' . __LINE__ . "<br />"; echo '当前文件绝对路径:' . __FILE__ . "<br />"; echo '当前文件所在的绝对路径的文件夹:' . __DIR__ . "<br />"; echo '返回类名::方法名:' . __METHOD__ . "<br />"; } } $moshu = new moshu(); $moshu->moshu();
The results are as follows:
当前类名:MoShu 当前方法名:moshu 当前文件中所在的行数:10 当前文件绝对路径:D:\xampp\htdocs\test\moshu.php 当前文件所在的绝对路径的文件夹:D:\xampp\htdocs\test 返回类名::方法名:MoShu::moshu
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
php curl batch processing to achieve controllable concurrent asynchronous operations
php method of using curl to forge source ip and refer
PHPAnalysis of Shared Memory Usage and Signal Control Example
The above is the detailed content of Detailed explanation and examples of php magic constants. For more information, please follow other related articles on the PHP Chinese website!