|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #81583 Accessing class constants on objects in string interpolation
Submitted: 2021-11-01 10:03 UTC Modified: 2021-11-01 13:17 UTC
Avg. Score:3.0 ± 2.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: php at crmteam dot cytainment dot de Assigned:
Status: Open Package: *General Issues
PHP Version: 8.0.12 OS: Debian 10
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:
6 + 3 = ?
Subscribe to this entry?

 [2021-11-01 10:03 UTC] php at crmteam dot cytainment dot de
The introduced feature ::class on objects is throwing a syntax error when being used in string concatenation using curly braces.

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"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-01 13:17 UTC]
-Summary: ::class on objects using string concatenation +Summary: Accessing class constants on objects in string interpolation -Type: Bug +Type: Feature/Change Request
 [2021-11-01 13:17 UTC]
This is not really specific to ::class, applies to $a::XYZ generally. In any case, this is clearly a feature request.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat May 28 14:05:47 2022 UTC