ID:               30934
 Comment by:       php-bugs at foomatic dot net
 Reported By:      jbs at fromru dot com
 Status:           Assigned
 Bug Type:         Feature/Change Request
 Operating System: *
 PHP Version:      5.*
 Assigned To:      andi
 New Comment:

> First 'self' is bound at compile time (that's the way OOP works).

Thats how Java works. Not All OO Languages do. PHP is a dynamic
language, and shouldn't really suffer a significant performance hit by
binding at run time (Especially considering it's still compiled, thus
bound, for every single request anyway). 

> what you want is something like 'called_class'

As long as it's bound at runtime, I don't particuarly care what it's
called. :-).


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

[2005-04-25 07:49:05] [EMAIL PROTECTED]

First 'self' is bound at compile time (that's the way OOP works).

Second what you want is something like 'called_class'. Assume you have
a static private member in your base class and a static function and
your derived class does not overload that function. If now your static
function is called with the derived class and 'self' would be changed
to the requested behavior php won't be able to access the property.
Thus you want an additional info maybe called 'used_class'.

Third to allow what you need a major change is needed that would slow
down php - every part of php code execution. And that will take a
while.

------------------------------------------------------------------------

[2005-04-25 06:24:04] php-bugs at foomatic dot net

Does anyone whats happening with this bug? Is it going to be fixed or
are the PHP devs just ignoring it?

Unless this is fixed (or a suitable workaround is added) I cannot put
common code that refers to static variables or methods in a base class,
resulting in significant code duplication. This is a huge issue, and is
a perfect example  of why PHP is regarded with contempt in many
circles.

My choices at the moment are to either continue hacking around it and
clean up once it's been fixed, or rewrite a significant amount of
legacy code in a real language. Given the rating of this bug, it looks
like I'm not the only one.

------------------------------------------------------------------------

[2005-04-12 13:28:53] [EMAIL PROTECTED]

I think this really needs to be addressed. For example the php manual
features a sample singleton implementation:
http://www.php.net/manual/en/language.oop5.patterns.php

Now how would one go about making it possible to extend the "Example"
class without having to cut and paste the singleton() method to this
extended class (one would probably also need to the instance property
to hold an array of instances keyed be the class name)? Not exactly in
the spirit of OOP imho.

It seems to me the best solution to retain this "speed optimization" of
resolving these things at compile time is to copy the implementations of
static items over to classes that extend that class before this
evaluation is done. Just a thought from an outside perspective, dunno
if this is feasible however in the ZE2 implementation.

------------------------------------------------------------------------

[2005-04-11 23:14:42] aknaub at 3st dot de

Sorry, but this quote is nonsense. Every real OOP 
language (Ruby, ObjC etc.) resolves static methods at 
runtime.

------------------------------------------------------------------------

[2005-04-11 13:50:15] jbs at fromru dot com

I've noticed some similar reports. For example, the one at
http://bugs.php.net/bug.php?id=30235.

Here is a quote:
>
> Sorry, you have a complete wrong idea og OO programming.
>
> Static methods are bound/resolved at compile time.
> That is the compiler can replace self with the current
> class.
>

So, it appears as it is a limitation of the compiler and the entire
object model.

I think such behavior makes inheritance of static methods useless
because even if a static method is inherited, it still functions as in
the class where it was declared. Moreover, inherited static methods are
using the static properties which were declared in the parent class but
not the inherited one.

So, in my opinion "self" keyword should be replaced with the name of
the inherited class during compiling. Or at least a new magic keyword
should be added and named like "this", for example.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/30934

-- 
Edit this bug report at http://bugs.php.net/?id=30934&edit=1

Reply via email to