RSS

__isset()

06 Jun

The __isset() magic method in PHP5 is called whenever isset function of PHP is called to check for undeclared data member. With the help of this method we can check for the undeclared variables in the code. We can also set appropriate error message while testing for variable names getting used in the Class.

<?php
class magicmethod
{
	function __isset($variablename)
	{
		echo "Variable '".$variablename."' not Set";
	}
}
$a = new magicmethod();
isset($a->name);
?>

Here i am trying to check whether the name attribute is set or not using isset function of PHP. But the name attribute is not defined inside magicmethod class so the PHP compiler call the __isset() method where an appropriate error message is displayed. Thus the output will be :

Variable ‘name’ not Set
 
Leave a comment

Posted by on June 6, 2011 in Magic Methods, PHP

 

Leave a comment