PHP __isset() is called whenever the calling code attempts to call PHP's isset() function on an invisible property.
It takes one argument - the property name - and should return true if the property is deemed to be "set," and false otherwise:
<?php class MyClass { public function __isset($propertyName) { return (substr($propertyName, 0, 4) =="test") ? true : false; }// www. ja v a 2s . c om } $testObject = new MyClass; echo isset($testObject->banana)."\n"; // Displays""(false) echo isset($testObject->testBanana)."\n"; // Displays"1"(true) ?>
__unset() is called when the calling code attempts to delete an invisible property with PHP's unset() function.
It shouldn't return a value, but should do whatever is necessary to "unset" the property (if applicable):
<?php class MyClass { public function __unset($propertyName) { echo"Unsetting property'$propertyName'\n"; }/*from w w w. j ava2 s . com*/ } $testObject = new MyClass; unset($testObject->banana); // Displays"Unsetting property'banana'" ?>
__callStatic() works like __call(), except that it is called whenever an attempt is made to call an invisible static method.
<?php class MyClass { public static function __callStatic($methodName, $arguments) { echo"Static method'$methodName'called with the arguments: \n"; foreach ($arguments as $arg) { echo"$arg \n"; }//from w w w.j av a 2s .c o m } } MyClass::randomMethod("apple","peach","strawberry"); ?>