Bug #76539 [Opn]: Trait attribute is set incorrectly when using self::class with another string

From: Date: Thu, 28 Jun 2018 09:01:50 +0000
Subject: Bug #76539 [Opn]: 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-216001@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: Open 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: Looks like something in 7.3 fixed this as a side-effect: https://3v4l.org/dQ6hM Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#216001) next »