php.net is implemented in C and under the covers it implements magic methods by attaching a table of function pointers to each object (called the object handlers). In most cases the default implementation of an object handler is to simply call the appropriate PHP method on the class.
For example, there is a __call object handler which calls the __call PHP magic method if it exists. Built in classes like SimpleXML and MySQLi use object handlers to implement whatever logic they need. All of this and a lot more besides is documented in Sara Golemans book.
In Project Zero we added magic methods like __call, __get and __set a long time ago. Over the Christmas break we finally got round to adding their static equivalents: __callStatic, __getStatic, __setStatic and __issetStatic.
Here's an example of how __callStatic can be used:
<?php
class Foo {
static public function __callStatic($a, $b) {
print "__callStatic [$a]\n";
}
}
foo::Test();
?>
We have also surfaced this feature into the Java Bridge:
<?php
java_import("java.lang.Integer", NULL, FALSE);
var_dump(Integer::$MIN_VALUE);
var_dump(Integer::$MAX_VALUE);
var_dump(Integer::toHexString("1234567890"));
var_dump(Integer::toOctalString("1234567890"));
// Signatures also work as normal!
$signature = new JavaSignature(JAVA_STRING);
var_dump(Integer::parseInt($signature, "1234567890"));
?>
This makes for a much cleaner syntax than using JavaClass. JavaClass was always something of an anomaly (er, hack) as it required the script to create an instance of an object just to access static class methods and properties.
More information about this feature will be available just as soon as the Project Zero documentation has rebuilt tonight [:o)
0 comments:
Post a Comment