Bug #72981 [Opn]: Interpolated strings cannot be dereferenced directly
| From: | cmb@php.net | Date: | Mon, 12 Mar 2018 13:35:04 +0000 |
| Subject: | Bug #72981 [Opn]: Interpolated strings cannot be dereferenced directly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-214300@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72981&edit=1
ID: 72981
Updated by: cmb@php.net
Reported by: nikic@php.net
Summary: Interpolated strings cannot be dereferenced directly
Status: Open
Type: Bug
Package: Scripting Engine problem
PHP Version: master-Git-2016-08-30 (Git)
Block user comment: N
Private report: N
New Comment:
> As of PHP 5.6 it is possible to write "foo"[0].
As of PHP 5.5.0, by the way.
> However, if the string uses interpolation this does not work and
> leads to a parse error.
Not sure, if we should try to fix this, since this feature appears
to be rarely useful, and since it is possible to dereference
arbitrary parenthesized expressions (as of PHP 7.0.0) which
appears to be more readable for complex cases at least. With
regard to Heredoc and Nowdoc direct dereferentiation seems to be
even more doubtful, even if the Flexible Heredoc and Nowdoc
Syntaxes RFC[1] will be implemented.
I suggest to mark this as documentation issue.
[1] <https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes>
Previous Comments:
------------------------------------------------------------------------
[2016-08-30 16:59:43] nikic@php.net
Description:
------------
As of PHP 5.6 it is possible to write "foo"[0]. However, if the string uses interpolation
this does not work and leads to a parse error.
Test script:
---------------
<?php
$bar = "bar";
var_dump("foo$bar"[0]);
Expected result:
----------------
string(1) "f"
Actual result:
--------------
Parse error: syntax error, unexpected '[', expecting ',' or ')'
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72981&edit=1