Bug #76539 [Opn->Ver]: Trait attribute is set incorrectly when using self::class with another string
Edit report at https://bugs.php.net/bug.php?id=76539&edit=1
ID: 76539
Updated by: kalle@php.net
Reported by: christian dot lerch89 at gmail dot com
Summary: Trait attribute is set incorrectly when using
self::class with another string
-Status: Open
+Status: Verified
Type: Bug
Package: Scripting Engine problem
Operating System: Ubuntu 18.04
PHP Version: 7.1Git-2018-06-28 (Git)
Block user comment: N
Private report: N
New Comment:
I added a test case for this in master to hopefully catch such a thing in the future, but the bug
still remains open for 7.1 & 7.2
Previous Comments:
------------------------------------------------------------------------
[2018-06-28 09:01:49] nikic@php.net
Looks like something in 7.3 fixed this as a side-effect: https://3v4l.org/dQ6hM
------------------------------------------------------------------------
[2018-06-28 08:53:33] christian dot lerch89 at gmail dot com
Description:
------------
When the value of a trait attribute is a concatenation of self::class (or __CLASS__) and another
string, the value of the very first instantiation persists.
This problem seems to be introduced at 7.1 and still shows up on 7.2.4.
You may try the example with >=7.0 here: http://sandbox.onlinephpfunctions.com/code/cced66bdfaf2dc5d09a042e4de1947bd8198b95d
Test script:
---------------
trait MyTrait {
protected $attr = self::class . 'Test';
public function test() {
return $this->attr;
}
}
class A {
use MyTrait;
}
class B {
use MyTrait;
}
$a = new A();
$b = new B();
Expected result:
----------------
ATest
BTest
Actual result:
--------------
ATest
ATest
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76539&edit=1
Thread (6 messages)