ID:               39177
 Updated by:       [EMAIL PROTECTED]
 Reported By:      acarheden at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: Windows 2K3 Server
 PHP Version:      5.1.6
 New Comment:

Duplicate of FR #34804.


Previous Comments:
------------------------------------------------------------------------

[2006-10-17 17:13:35] acarheden at gmail dot com

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 this bug report at http://bugs.php.net/?id=39177&edit=1

Reply via email to