PHP Magic Method

Link
__set and __get

PHP provides a pair of magic methods that deal with non-existent or private property access:

  • The __get() method is called whenever you attempt to read a non-existing or private property of an object.
  • The __set() method is called whenever you attempt to write to a non-existing or private property of an object.
    Code

__call 

Similar to the __get() and __set() methods, the __call() magic method is called automatically when a nonexistent method of the class is called. The __call() method is rarely used in practice. It is useful when you to create a wrapper class that wraps the existing APIs.
we can use __call to implement overloading in php. SO


Notice that the constructor and destructor methods ( __construct() and __destruct() ) are also magic methods. For other magic methods, check it out the PHP magic methods.

 

Advertisements
Posted in PHP

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s