PHP 5 Tutorial – __get() Magic Method
This tutorial will guide you through the __get() Magic Method. The __get Magic method in PHP5 gets called when accessing the value of an undeclared or undefined attributes of an class. With this method the programmer can keep track on the variables which are not defined inside the class.
Syntax:
function __get($data) { //$data holds the name of the undefined attributes getting called. }
Example: __get Magic Method Usage
< ? class magicmethod { function __get($data) { echo "Error accessing undefined attributes"; echo "attributes Called:".$data; } } $a = new magicmethod(); echo $a->setData; ?>
Output:
Error accessing undefined attributes
attributes Called:setData
Explanation for the Example:
Here i am trying to echo an attribute setData of magicmethod class.
But in the magicmethod class setData is not defined so the php compiler excutes __get() magic method and displays error message.
Custom Search
Popular Articles:
- PHP5 Tutorial – __unset() Magic Method
- PHP5 Tutorial – __call() Magic Method
- PHP5 Tutorial – __isset() Magic Method
- OOPS in PHP 5 – instanceOf Operator
- PHP5 Tutorial – __sleep() Magic Method
- PHP5 Tutorial – __toString() Magic Method
- Writing HTML Scrapper in PHP
- PHP5 Tutorial – __clone Magic Method
- OOPS in PHP 5 Tutorial – Defining Class Constants
- Singleton Class in PHP 5



































Hello…Man i just love your blog, keep the cool posts comin..holy Tuesday