PHP 5 Tutorial - __isset() Magic Method
This tutorial will guide you through the __isset() Magic Method. 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.
Syntax:
function __isset($dt) { //$dt is the Variable Name that isset is supposed to check. }
Example - __isset() magic method usage
< ? class magicmethod { function __isset($variablename) { echo "Variable '".$variablename."' not Set"; } } $a = new magicmethod(); isset($a->name); ?>
Output: Variable ‘name’ not Set
Explanation for the Example:
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.
Related Post
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.












































Comments
No comments yet.
Leave a comment