Magic Methods

Method Signiture When Called Parameters Passed Values Return Type What is it for? Link
__construct() __construct ([ mixed $args = "" [, $... ]] ) : void When an object is instantiated mixed $args Void Passing arguments when the object is instantiated https://www.php.net/manual/en/language.oop5.decon.php#object.construct
__destruct() __destruct ( void ) : void When an object is destoryed. Void Void Clean up needed when an object is destroyed. https://www.php.net/manual/en/language.oop5.decon.php#object.destruct
__call() public __call ( string $name , array $arguments ) : mixed When invoking inaccessible methods in an object context. string $name , array $arguments The $name argument is the name of the method being called. The $arguments argument is an enumerated array containing the parameters passed to the $name'ed method. mixed Handles the call of non existent methods https://www.php.net/manual/en/language.oop5.overloading.php#object.call
__callStatic() public static __callStatic ( string $name , array $arguments ) : mixed When an unaccessible method is called staticly. string name, array arguments name: the name of the method called. arguments: an array of parameters passed when calling the method. mixed Class::methodWhichDoesntExist() https://www.php.net/manual/en/language.oop5.overloading.php#object.callstatic
__get() public __get ( string $name ) : mixed When reading data from inaccessible (protected or private) or non-existing properties. string $name The $name argument is the name of the property being interacted with mixed Handles the call of non existent or private/protected properties https://www.php.net/manual/en/language.oop5.overloading.php#object.get
__set() public __set ( string $name , mixed $value ) : void When writing data to unaccessible properites. string name, mixed value name: name of the propertie, value: the value to set Handling data or setting properties or which are private, protected or non-existent. https://www.php.net/manual/en/language.oop5.overloading.php#object.set
__isset() public __isset ( string $name ) : bool When calling isset() or empty() on inaccessible (protected or private) or non-existing properties. string $name The $name argument is the name of the property being interacted with. bool Alter the behavious of isset() or empty() https://www.php.net/manual/en/language.oop5.overloading.php#object.isset
__unset() public __unset ( string $name ) : void When unset is called on unaccisble properites. string name The name of the property to unset Unsetting data for properties which are private, protected or non-existent. https://www.php.net/manual/en/language.oop5.overloading.php#object.unset
__sleep() public __sleep ( void ) : array Prior to any serialization. Void array serialize() checks if your class has a function with the magic name __sleep(). If so, that function is executed prior to any serialization. https://www.php.net/manual/en/language.oop5.magic.php#object.sleep
__wakeup() __wakeup ( void ) : void When an object is unserialized. Void Void Any setup needed when unserializing and object. https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup
__toString() public __toString ( void ) : string When the class is treated as a string Void string Allows a class to decide how it will react when it is treated like a string https://www.php.net/manual/en/language.oop5.magic.php#object.tostring
__invoke() __invoke ([ $... ] ) : mixed When an object is called as a function. Optional arguments Mixed If the object needs to be callable. https://www.php.net/manual/en/language.oop5.magic.php#object.invoke
__set_state() static __set_state ( array $properties ) : object When var_export() is used on the object array $properties array containing exported properties in the form array('property' => value, ...) object This static method is called for classes exported by var_export() since PHP 5.1.0. https://www.php.net/manual/en/language.oop5.magic.php#object.set-state
__clone() __clone ( void ) : void When an object is cloned. Void Void Usually if an object is cloned but not all properties should be the same. https://www.php.net/manual/en/language.oop5.cloning.php#object.clone
__debugInfo() __debugInfo ( void ) : array When var_dump() is used on the object. Void Array Showing relevant info when debugging the object. https://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo