Home  >  Article  >  Backend Development  >  Detailed explanation and examples of php magic constants

Detailed explanation and examples of php magic constants

墨辰丷
墨辰丷Original
2018-05-29 17:45:301585browse

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 &#39;当前类名:&#39; . __CLASS__ . "<br />";
 echo &#39;当前方法名:&#39; . __FUNCTION__ . "<br />";
 echo &#39;当前文件中所在的行数:&#39; . __LINE__ . "<br />";
 echo &#39;当前文件绝对路径:&#39; . __FILE__ . "<br />";
 echo &#39;当前文件所在的绝对路径的文件夹:&#39; . __DIR__ . "<br />";
 echo &#39;返回类名::方法名:&#39; . __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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn