__isset and __unset magic methods in php are opposite of each other. __isset magic methods executes when function isset() is applied on property which is not available or not defined. It takes name of the parameter as an argument.

__unset magic method triggers when unset() method is applied on the property which is either not defined or not accessible. It takes name of the parameter as an argument. Following is example of __isset and __unset magic method in php


class Hello { 
  function __isset($name) { 
    echo "variable $name is called isset <br>"; 
  } 
  function __unset($name) { 
    echo "variable $name is called for unset<br>"; 
  } 
} 
$obj = new Hello(); 
isset($obj->x); 
unset($obj->y);

Output--- 
variable x is called for isset
variable y is called for unset
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

WordPress.com.

Up ↑

%d bloggers like this: