__call(), __get() and __set() are so called magic functions of PHP-classes. __set() is called, when you’re trying to overload a property of a class, __get() is called, when you trying to fetch a property which is undefined and __call is executed if you’re going to call a method which is not defined. Example:
class TestThis should be enough, to understand what this functions are doing. Now you can modify the magic functions to log its error messages or to trigger a warning. One hint: Also it seems, it’s not a good idea to throw an exception, because this will lead to silent stops in your program in combination with
{ public function __set( $name, $value ) { echo “Name: {$name}\n”; echo “Value: {$value}\n”; } public function __get( $name ) { echo “Name: $name\n”; } public function __call( $method, $parameter ) { echo “Method {$method} called with following parameter:\n”; var_dump( $paramter ); } }
register_callback_function(). A good idea is to create a base-class, which provides such QA-mechanisms for free and all of your classes are children of this class. Also it would be a good idea if something like this would be implemented in PHP.
Filed under Code, Magic function, OOP, PHP, Quality assurance, Technology & no comments & no trackbacks
Trackback specific URI for this entry