Share on Google+Share on Google+

PHP Magic Methods

In this PHP tutorial you will come to know about various methods which are called as magic methods. This is the first page on this topic and the subsequent pages will help you to understand each and every magic method precisely.

Magic Methods in PHP:

In PHP there are so many methods are included in recent versions, magic methods are one of them. The magic methods are listed below:

  1. __construct()

  2. __destruct()

  3. __call()

  4. __callStatic()

  5. __get()

  6. __set()

  7. __isset()

  8. __unset()

  9. __sleep()

  10. __wakeup()

  11. __toString()

  12. __invoke()

  13. __set_state()

  14. __clone()

In the above list of the magic methods it is very easy to identify that every magical method name is started with " __ " sign. We can not declare any user-defined functions with __ sign, and we can not use the magic methods name in any user-defined functions.

The following links will describe magic methods:


PHP Constructor and Destructor
In this current tutorial we will study about constructor and destructor of OOP.Like other OOP based languages PHP also supports constructor method for classes. As any other language's constructor method, in PHP constructor method is called for every object creation.
PHP Sleep Wakeup Method
This is one of the magic method provided by PHP. The __sleep function in PHP is useful when we have very large objects in our program and we do not want to save the object completely and __wakeup() of PHP is used to reestablish the database connections that may have been lost during any phenomenon.
PHP toString Function
In PHP 5.3.0 a method has been introduced called toString(), basic functionality of the method is to print an object, how? current tutorial is trying to focus on this topic.


Posted on: March 4, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null