From: acarheden at gmail dot com Operating system: Windows 2K3 Server PHP version: 5.1.6 PHP Bug Type: Feature/Change Request Bug description: Need mechanism to identifed calling class in static methods
Description: ------------ This bug is a duplicate of all of these bugs, but I have a new argument. I've also filed it correctly as a feature request: http://bugs.php.net/bug.php?id=30140 http://bugs.php.net/bug.php?id=30423 http://bugs.php.net/bug.php?id=30934 http://bugs.php.net/bug.php?id=30235 When you call a static method on a subclass, the superclass has no way of knowning what, if any, subclass it was called from. Say you wanted to implement an Object-Relational Model like ActiveRecord (Ruby) in PHP (I do). You write an abstract ActiveRecord class with a static method find() that gets records from the database. Users write some subclass, the name of which coorisponds to a database table. In Ruby's ActiveRecord something like class User extends ActiveRecord {} is my entire implementation of the User class. I call User::find() and it returns all the User records (As User objects) from the database. The same thing is impossible in PHP because ActiveRecord::find() doesn't know it was called as User::find(). I understand that C++ and Java don't work the way Ruby does. I also understand that it's not a simple change to make and that it may have performance implications. But Ruby is slower, doesn't work well on Windows, and doesn't have as much code available as PHP, so it would be specacular if PHP could provide such functionality as well. Also, shouldn't you simply be able to include some method like get_called_class() that walks the stack trace to find this info. That doesn't seem like it should be very difficult OR impact the performance of things that don't use the new functionality. Oh, and one more thing. Pleeeeaaassseeee! Reproduce code: --------------- class test { static function whoami() { print "I am " . __CLASS__; // Maybe __CALLED_CLASS__ } } class test1 extends test { } test::whoami -> I am test Expected result: ---------------- I expect the results I get... Actual result: -------------- ..but I'd LIKE a way to get 'test1'. -- Edit bug report at http://bugs.php.net/?id=39177&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39177&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39177&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39177&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39177&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39177&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39177&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39177&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39177&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39177&r=support Expected behavior: http://bugs.php.net/fix.php?id=39177&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39177&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39177&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39177&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39177&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39177&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39177&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39177&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39177&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39177&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39177&r=mysqlcfg