__set() and __get() magic method in oop

/*__set() magic method used when a value is to be assigned for an undefined variable within a class … when an undefined variable is to be assign __set() automatically called .. __set() method put those undefined variable into a array … so that it accept two parameter .. one is the index number another is the value …

__get() megic method used to show the undefined variable … display the undefined variable it called automatically ..*/

class ap
public $a;
public $un_var = array();

public function __set($y,$z)
$this->un_var[$y] = $z;

public function __get($y)
echo $this->un_var[$y];

$object = new ap();

$object->name = “Khdandaker Fazle Elahi”;
$object->age = 23;
echo $object->name.”\t “.$object->age;



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 )

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