/usr/portage

Quality assurance with __call(), __get(), __set() 0

__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 Test
{ 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 ); } }
This 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 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 , , , , , & no comments & no trackbacks

Trackbacks

Trackback specific URI for this entry

No Trackbacks

Comments

No comments

Add a Comment & let me know what you think