PHP5 Tutorial – __call() Magic Method
This tutorial will guide you through the __call() Magic Method. The __call Magic method in PHP5 get called when accessing an undeclared or undefined methods of an class. With this magic method the programmer can keep track on the undeclared method which are not defined inside the class.
Syntax:
< ? function __call($data,$argument) { //$data holds the name of the undefined method getting called. //$argument holds the argument passed to the method. } ?>
Example – __call Magic Method
< ? class magicmethod { function __call($data,$argument) { echo "Error accessing undefined Method"; echo "Method Called: ".$data; echo "Argument passed to the Method: ".$argument; } } $a = new magicmethod(); echo $a->setData(); //Calling setData method ?>
Output:
Error accessing undefined Method
Method Called: setData
Argument passed to the Method: Array (Array of the Argument Passed)
Explanation for the Example:
Here i am trying to call setData method of magicmethod class.
Now in the magicmethod class setData is not defined so the php compiler excutes __call() magic method and displays error message.
Custom Search
Popular Articles:
- Reading Remote URL HTML Source in PHP
- OOPS in PHP 5 Tutorial – Exploring Inheritance
- PHP5 Tutorial – Parsing XML documents in PHP5 using SimpleXML
- OOPS in PHP5 – __construct() Method
- PHP5 Tutorial – __autoload Magic Method
- OOPS in PHP 5 Tutorial – Parent Keyword
- Database Class in PHP5
- Singleton Class in PHP 5
- Writing HTML Scrapper in PHP
- OOPS in PHP5 – Define Attributes for Class



































__call is not worked at the time of call a undefined member function using scope resolution operation..
ex: magicmethod::setData()