The Magic constant PHP provides a lot of predefined constants to any script it runs, and our usual PHP magic constants are __class__ __function__ __line__ __file__ __dir__ __method__, This article introduces PHP Magic constants to you through examples of PHP
Instance:
Classpublicfunction Moshu () { echo__class__ . "
"; Echo __function__ . "
"; Echo __line__ . "
"; Echo __file__ . "
"; Echo ' folder where the current file is located in the absolute path: '. __dir__. "
"; Echo __method__ . "
"; }} $moshu New Moshu (); $moshu->moshu ();
Copy the code here to run a
The results are as follows:
Current class Name: Moshu Current method Name: Moshu the number of lines in the current file: the Absolute path of the current file: D: \xampp\htdocs\test\moshu. The folder of the absolute path where the current file of PHP is located: D:\xampp\htdocs\test Returns the class name :: Method Name: Moshu::moshu
The above describes the PHP magic constants examples, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.