Discussion:
[PHP-DEV] Protected static props redeclared as public share value across classes
(too old to reply)
Robin Fernandes
2008-02-26 17:36:30 UTC
Permalink
Hi Marcus,
I checked it out in more detail and it is indeed broken as in it is not
consistent
If possible, I'd like to revive this discussion. Patch included. :)
History: http://thread.gmane.org/gmane.comp.php.devel/47956/focus=47956

To summarize, we agree that there is an inconsistency related to
static property inheritance, because:

--> In the following case, A::$p and B::$p share the same value:
class A { protected static $p; } class B extends A { public static $p; }

--> Yet in the following cases, A::$p and B::$p have two separate values:
class A { protected static $p; } class B extends A { protected static $p; }
class A { public static $p; } class B extends A { public static $p; }

You originally suggested fixing the inconsistency by changing the last
2 cases, so that A::$p and B::$p always share the same value. However,
that approach raised some concerns described by myself and Jochem, for
example:
--> Inconsistency with overridden methods
--> Inconsistency with shadowed class constants.

Consequently, I'd like to propose resolving this by changing the first
case, so that A::$p and B::$p always have separate values.

Here's a patch that implements this. It includes relevant changes to
existing tests, plus some supplementary tests to address Jochem's
concern about the impact on LSB.

Patch against snap php6.0-200802251530: http://pastebin.ca/919094
Disclaimer: I am not an internals expert - patch might overlook some
cases, feedback welcome. :)

Let me know what you think.

Regards,
Robin
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Robin Fernandes
2008-03-03 15:58:19 UTC
Permalink
Post by Robin Fernandes
I checked it out in more detail and it is indeed broken as in it is not
consistent
If possible, I'd like to revive this discussion. Patch included. :)
For the record, with helly's agreement I committed the patch to 5_3
and HEAD - thanks helly!

Ilia / others,
How would you feel about me back porting this to 5_2?
The purpose of the change is to make static property inheritance rules
more consistent - both amongst themselves and compared to static
method inheritance rules.

The patch does introduce a small change in behaviour (the old
behaviour is imho buggy). See previous posts in this thread for the
details ( http://turl.ca/phhhf ) and here for an example:
http://pastebin.ca/926106 .

I know at least a couple of people would rather this fix be 5.3+ only.
More opinions welcome!

Cheers,
Robin
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...