Detailed explanation and examples of php magic constants

墨辰丷
Release: 2023-03-28 12:08:02
Original
1545 people have browsed it

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();
Copy after login

The results are as follows:

当前类名:MoShu
当前方法名:moshu
当前文件中所在的行数:10
当前文件绝对路径:D:\xampp\htdocs\test\moshu.php
当前文件所在的绝对路径的文件夹:D:\xampp\htdocs\test
返回类名::方法名:MoShu::moshu
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!