php.net |  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
Votes:1
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
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: divinity76 at gmail dot com
New email:
PHP Version: OS:

 

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

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

Expected result:
----------------
123456

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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-12 14:15 UTC] nikic@php.net
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: Wed Apr 24 22:01:30 2024 UTC