Bug #70437 [Asn]: Changes to static properties in trait methods are not reflected in the class
| From: | bwoebi@php.net | Date: | Mon, 07 Sep 2015 11:10:57 +0000 |
| Subject: | Bug #70437 [Asn]: Changes to static properties in trait methods are not reflected in the class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195837@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70437&edit=1
ID: 70437
Updated by: bwoebi@php.net
Reported by: davey@php.net
Summary: Changes to static properties in trait methods are
not reflected in the class
Status: Assigned
Type: Bug
Package: Scripting Engine problem
Operating System: OSX/Linux
PHP Version: 7.0.0RC2
Assigned To: bwoebi
Block user comment: N
Private report: N
New Comment:
Is it by design?
We don't know, it's neither documented nor mentioned in the original RFC.
Heck, the RFC itself proposed even a singleton trait.
With current semantics that trait could be used only exactly once, because the trait shares the
static property. I guess that's not the purpose of traits, it's about horizontal *reuse*.
Hence each class should have its own static properties and never use the static property of the
trait.
Also, by the way, if they were supposed to be independent, then the classes shouldn't be copied
the traits static properties (and methods too) into them.
We should have one or the other behavior, but having both behaviors is very confusing.
Previous Comments:
------------------------------------------------------------------------
[2015-09-07 11:02:00] gron@php.net
This is by design, changing that is a BC issue.
The design is chosen based on the desired 'copy-down' semantics of traits.
Static properties of traits are independent of the ones of classes using the trait.
Changing it means you break the copy-down semantics by adding another corner case where it is not
consistent.
------------------------------------------------------------------------
[2015-09-07 10:45:15] bwoebi@php.net
Did you checkout the patch? It's always accessing the class' static property now as far as
I see?
------------------------------------------------------------------------
[2015-09-07 10:39:25] davey@php.net
The issue isn't when calling the method directly on the trait but also when calling it on the
implementing class. Any changes to static properties within trait methods called on the implementing
class are only reflected within the traits copy of it; rather than the implementing classes copy as
it should be.
------------------------------------------------------------------------
[2015-09-07 09:15:15] bwoebi@php.net
Totally agreeing with Nikita here; I've just attached a small PR: https://github.com/php/php-src/pull/1506
------------------------------------------------------------------------
[2015-09-07 03:53:33] nikic@php.net
Imho the bug here is that we allow calls to static methods on traits. I don't think that's
supposed to work and we should add this forgotten check in PHP 7.
------------------------------------------------------------------------
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=70437
--
Edit this bug report at https://bugs.php.net/bug.php?id=70437&edit=1