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

 ID:                 30934
 Comment by:         jeff at goblinoid dot co dot uk
 Reported by:        jbs at fromru dot com
 Summary:            Special keyword 'self' inherited in child classes
 Status:             Not a bug
 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:

$this doesn't work for static methods, using static:: instead of self:: will 
cause 
the binding to be done at runtime, and work as required. 
http://php.net/manual/en/language.oop5.late-static-bindings.php


Previous Comments:
------------------------------------------------------------------------
[2011-02-04 19:50:39] tim at gurka dot se

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

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

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


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

    https://bugs.php.net/bug.php?id=30934


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

Reply via email to