__isset() and __unset() magic method in oop

<?php
/*__isset() magic method receives a parameter – the value of which is the name of the variable that the program wants to test if the variable is set or not.

__unset() magic method receives a parameter – the value of which is the name of the variable that the program wants to unset.*/
class epico
{
private $un_var = array();
function __set($a,$b)
{
$this->un_var[$a] = $b;
}
function __get($a)
{
echo $this->un_var[$a];
}
function __isset($a)
{
return isset($this->un_var[$a]);
}
function __unset($a)
{
unset($this->un_var[$a]);
//echo “The variable is unset”;
}
}

$ob = new epico();
$ob->name = “Khandaker Fazle Elahi”;
echo isset($ob->name);
echo unset($ob->name);
?>

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