Bug #76539 [Ver->Csd]: Trait attribute is set incorrectly when using self::class with another string

From: Date: Mon, 02 Mar 2020 20:42:20 +0000
Subject: Bug #76539 [Ver->Csd]: Trait attribute is set incorrectly when using self::class with another string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225846@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76539&edit=1

 ID:                 76539
 Updated by:         nikic@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:             Verified
+Status:             Closed
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Ubuntu 18.04
 PHP Version:        7.1Git-2018-06-28 (Git)
-Assigned To:        
+Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

Closing as this is fixed per previous comments.


Previous Comments:
------------------------------------------------------------------------
[2018-07-09 17:27:14] 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>

------------------------------------------------------------------------
[2018-07-04 17:51:23] 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-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)

« previous php.bugs (#225846) next »