PHP magic functions

PHP 5 certainly has some magical facts, it has reserved all the function names starting with __ as magical.

The following function names :

__construct(), __destruct(), 

__unset(), __isset(),

 __sleep(), __wakeup(),

__call(), __callStatic(), 

 __toString(),  __clone()

__get(), __set(), 

__invoke(), __set_state()

are magical in PHP classes. Unless and until you want the magic functionality, you cannot have functions with these names in any of your classes.

Magic functions allow the programmers to perform difficult tasks effortlessly and are powerful time-savers for loading resources automatically, or for overloading methods and properties of classes.

Though its not a new concept for experienced programmers but for beginners its a life saver, though a bit difficult to understand at first, but once you learn to use it, you will fall in love with these functions.

A detailed and complete tutorial on all the above functions is just a click away.




Print Friendly

Leave a Reply

Your email address will not be published. Required fields are marked *