|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76539 Trait attribute is set incorrectly when using self::class with another string
Submitted: 2018-06-28 08:53 UTC Modified: 2020-03-02 20:42 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: christian dot lerch89 at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.1Git-2018-06-28 (Git) OS: Ubuntu 18.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: christian dot lerch89 at gmail dot com
New email:
PHP Version: OS:


 [2018-06-28 08:53 UTC] christian dot lerch89 at gmail dot com
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:

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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-28 09:01 UTC]
Looks like something in 7.3 fixed this as a side-effect:
 [2018-07-04 17:51 UTC]
-Status: Open +Status: Verified
 [2018-07-04 17:51 UTC]
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
 [2018-07-09 17:27 UTC]
> Looks like something in 7.3 fixed this as a side-effect: […]

FWIW, that was the IS_CONSTANT removal[1].

[1] <>
 [2020-03-02 20:42 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-03-02 20:42 UTC]
Closing as this is fixed per previous comments.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Apr 02 07:01:23 2020 UTC