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

 ID:                 30934
 Comment by:         tim at gurka dot se
 Reported by:        jbs at fromru dot com
 Summary:            Special keyword 'self' inherited in child classes
 Status:             Bogus
 Type:               Feature/Change Request
 Package:            Feature/Change Request
 Operating System:   *
 PHP Version:        5.*
 Assigned To:        andi
 Block user comment: N
 Private report:     N

 New Comment:

The problem in the original comment could be avoided by using $this
instead of self.


Previous Comments:
------------------------------------------------------------------------
[2005-04-27 18:59:52] [email protected]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is expected behavior. self:: binds statically to its class (to the
best of my knowledge other languages like C++ don't support this either
as they require to explicitly use the class name). There are actually
advantages also to this approach as they allow you to protect and
encapsulate functinality.



------------------------------------------------------------------------
[2005-04-25 21:14:45] [email protected]

>> 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



It is not really a matter of performance here. It is just a different
model of acting. And it is the way static works correct. If you read the
example outline, you'll find out that it cannot work in a different way.
The only thing one can do here is to eventually add what you want
somehow.

------------------------------------------------------------------------
[2005-04-25 10:39:54] php-bugs at foomatic dot net

> 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. :-).

------------------------------------------------------------------------
[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.

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


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/bug.php?id=30934


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

Reply via email to