PHP code for magic method

php magic method are as below.

  • __set

  • __get

  • __isset

  • __unset

Example :

<?php
//code by aryatechno for Method Overloading

class Aryatechno
{
function __set($name,$val)
{
echo "<br/> __set magic method is called when writing value into inaccessiable property";
echo "<br/> Inaccessiable variable Name :".$name;
echo "<br/> variable value :".$val;

}

function __get($name)
{

echo "<br/> __get magic method is called when reading inaccessiable property";
echo "<br/> Inaccessiable variable Name :".$name;

}

function __isset($name)
{
echo "<br/> __isset magic method is called when isset() method is called for inaccessiable property";
echo "<br/> variable Name :".$name;
}

function __unset($name)
{
echo "<br/> __unset magic method is called when unset() method is called for inaccessiable property";
echo "<br/> Inaccessiable variable Name :".$name;
}


}

$obj = new Aryatechno;

$obj->i=100;

echo $obj->j;
isset($obj->p);

unset($obj->p);

?>

Output :

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

88152