Req #81583 [Com]: Accessing class constants on objects in string interpolation

From: Date: Tue, 06 Dec 2022 08:16:55 +0000
Subject: Req #81583 [Com]: Accessing class constants on objects in string interpolation
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243051@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81583&edit=1 ID: 81583 Comment by: Aleta3215acias at gmail dot com Reported by: php at crmteam dot cytainment dot de Summary: Accessing class constants on objects in string interpolation Status: Open Type: Feature/Change Request Package: *General Issues Operating System: Debian 10 PHP Version: 8.0.12 Block user comment: N Private report: N New Comment: Because "constants inside quotes are not printed". The correct form is: echo "This is a constant: " . CONSTANT; The dot is the concatenation operator. (https://www.dgcustomerfirst.win/)github.com Previous Comments: ------------------------------------------------------------------------ [2021-11-01 13:17:27] nikic@php.net This is not really specific to ::class, applies to $a::XYZ generally. In any case, this is clearly a feature request. ------------------------------------------------------------------------ [2021-11-01 10:03:59] php at crmteam dot cytainment dot de Description: ------------ The introduced feature ::class on objects is throwing a syntax error when being used in string concatenation using curly braces. Error: PHP Parse error: syntax error, unexpected token "}", expecting "->" or "?->" or "{" or "[" in php shell code on line 1 Test script: --------------- class Test {}; $a = new Test(); echo "Test " . $a::class; echo "Test {$a::class}"; Expected result: ---------------- In my opinion the lines 3 and 4 should output the same result "Test Test" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81583&edit=1

« previous php.bugs (#243051) next »