php.net |  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
Votes:1
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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-28 09:01 UTC] nikic@php.net
Looks like something in 7.3 fixed this as a side-effect: https://3v4l.org/dQ6hM
 [2018-07-04 17:51 UTC] kalle@php.net
-Status: Open +Status: Verified
 [2018-07-04 17:51 UTC] kalle@php.net
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] cmb@php.net
> Looks like something in 7.3 fixed this as a side-effect: […]

FWIW, that was the IS_CONSTANT removal[1].

[1] <https://github.com/php/php-src/commit/ef5ea48741a1d227a10a6654c1a8cc2f02dd414f>
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Dec 10 09:01:25 2018 UTC