|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #81241 quoted strings should support "{$this::constant}"
Submitted: 2021-07-09 13:10 UTC Modified: 2021-07-12 14:15 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: divinity76 at gmail dot com Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: Next Minor Version OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: divinity76 at gmail dot com
New email:
PHP Version: OS:


 [2021-07-09 13:10 UTC] divinity76 at gmail dot com
the same way "{$this->foo}" and $this->foo and this::CONSTANT is legal, "{$this::CONSTANT}" should also be legal

Test script:
class C{
    const CON=456;
    function f(){
        echo "123{$this::CON}";
(new C())->f();

Expected result:

Actual result:
Parse error: syntax error, unexpected token "}", expecting "->" or "?->" or "{" or "[" in /in/PIN5O on line 5


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-12 14:15 UTC]
The current limitation here is that that it start's with {$ and the contents of {} are a "variable". Class constants aren't considered a variable. This could be relaxed in two ways:

 * Specifically allow class constants in addition to variables.
 * Allow any expression (subject to the limitation that it must start with $). This would also make something like "{$a + $b}" valid, but not "{1 + $a}".

Both are backwards compatible, in that they only allow things that were previously a syntax error. This is unlike the case where "{any expression}" is allowed, which would be a major break.

In any case, such a change would need an RFC.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 07:01:30 2024 UTC