PHP Magic methods and Magic variables
Magic Method:
PHP treats all class methods starting with __ (two underscores) as a magic method;
- __construct (), construction method;
- __destruct (), destructor;
- __get (String $name) is called when accessing and setting a member variable that does not exist in the class;
__set (String $name, mixed $value) is called when accessing and setting a member variable that does not exist in the class;
__call (string $name, array $arguments) is called when a method that does not exist in the class is called;
- __tostring () is called when the object is converted to string;
- __clone (), cloning;
Magic constants:
A constant with two _ starts and ends for the magic constant;
- The current line number in the file __line__.
- __file__ the full path and filename of the file;
- __dir__ the directory where the files are located;
- __function__, function name;
- __class__, the name of the class;
- __method__-class method name;
- __NAMESPACE__ the name of the current namespace
PHP Magic methods and Magic variables