🐘 PHP Beginner

What are PHP magic methods?

Answer

Magic methods are special methods that PHP calls automatically in response to certain actions. They all start with a double underscore (__). Key magic methods: __construct() (object creation), __destruct() (object destruction), __get($name) and __set($name, $value) (accessing/setting inaccessible properties), __isset($name), __unset($name), __call($name, $args) (calling inaccessible methods), __callStatic($name, $args) (calling inaccessible static methods), __toString() (convert object to string — called when object is used as string), __invoke() (called when object is used as a function), __clone() (called when object is cloned with clone), and __debugInfo() (controls var_dump output).