Req #81241 [Opn]: quoted strings should support "{$this::constant}"
| From: | nikic@php.net | Date: | Mon, 12 Jul 2021 14:15:16 +0000 |
| Subject: | Req #81241 [Opn]: quoted strings should support "{$this::constant}" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234975@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81241&edit=1
ID: 81241
Updated by: nikic@php.net
Reported by: divinity76 at gmail dot com
Summary: quoted strings should support "{$this::constant}"
Status: Open
Type: Feature/Change Request
Package: Scripting Engine problem
PHP Version: Next Minor Version
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2021-07-09 13:10:40] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81241&edit=1