|  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: 2018-07-09 17:27 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:
Status: Verified 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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
9 + 13 = ?
Subscribe to this entry?

 [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] <>
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Oct 20 21:01:27 2019 UTC