From: Operating system: Windows XP PHP version: 5.3.2 Package: Reflection related Bug Type: Feature/Change Request Bug description:instanceof for static calls
Description: ------------ Hy guys, Here's a problem i faced today : i wanted to know if a base and derived class having only static functions and using both late static binding were an implementation of a specific interface. The problem was that the class base needed to know if its child implemented a specific interface. Not easy to explain, the code is easier for a better comprehension : Test script: --------------- <?php interface iTest { } class base { public static function create() { if (self instanceof iTest) echo 'iTest'; } } class child extends base implements iTest { } child::create(); ?> Expected result: ---------------- Normally the result should be 'iTest' because the class 'child' implements iTest Actual result: -------------- Doesn't execute. Here's the solution i found : i used the ReflectionCLass to emulate that feature <?php interface iTest { } class base { public static function create() { $r = new ReflectionClass(static::$SELF); if (in_array('iTest', $r->getInterfaceNames())) echo 'iTest'; } } class child extends base implements iTest { protected static $SELF = __CLASS__; } child::create(); ?> -- Edit bug report at http://bugs.php.net/bug.php?id=51544&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51544&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51544&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51544&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51544&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51544&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51544&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51544&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51544&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51544&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51544&r=support Expected behavior: http://bugs.php.net/fix.php?id=51544&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51544&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51544&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51544&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51544&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51544&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51544&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51544&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51544&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51544&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51544&r=mysqlcfg