php.net |  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: 2024-07-19 21:47 UTC
Votes:2
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: cmb (profile)
Status: Feedback Package: *General Issues
PHP Version: 8.0.12 OS: Debian 10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at crmteam dot cytainment dot de
New email:
PHP Version: OS:

 

 [2021-11-01 10:03 UTC] 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"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-01 13:17 UTC] nikic@php.net
-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] nikic@php.net
This is not really specific to ::class, applies to $a::XYZ generally. In any case, this is clearly a feature request.
 [2024-07-19 21:47 UTC] cmb@php.net
Are you still interested in this feature?
 [2024-07-19 21:47 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 27 00:01:30 2024 UTC