Bug #70437 [Asn]: Changes to static properties in trait methods are not reflected in the class

From: Date: Mon, 07 Sep 2015 10:45:16 +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-195833@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: Did you checkout the patch? It's always accessing the class' static property now as far as I see? Previous Comments: ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ [2015-09-06 14:32:49] davey@php.net Description: ------------ If you have a trait that defines a static property, and you modify said property from within a trait inherited method, the modifications are done to a trait instance of the property, as opposed to the inherited-from-trait static property within the class. The behavior differs slightly in PHP 5.4.7 - 5.5.29 in that if the methods are instance methods, then they will correctly modify the inherited-from-trait static property, but are broken for static methods. 5.6.0+ has the same behavior for static and instance methods. Test script: --------------- Static methods: https://3v4l.org/UZ6gq Instance methods: https://3v4l.org/piUFm Expected result: ---------------- Should modify the inherited-from-trait static property within the class Actual result: -------------- Modifies a trait-specific copy of the static property ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70437&edit=1

« previous php.bugs (#195833) next »