php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72981 Interpolated strings cannot be dereferenced directly
Submitted: 2016-08-30 16:59 UTC Modified: 2020-03-03 11:02 UTC
From: nikic@php.net Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: master-Git-2016-08-30 (Git) 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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nikic@php.net
New email:
PHP Version: OS:

 

 [2016-08-30 16:59 UTC] 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 ')'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-12 13:35 UTC] cmb@php.net
> 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>
 [2020-01-08 13:43 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2020-03-03 11:02 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2020-03-03 11:02 UTC] nikic@php.net
This is supported as of PHP 8.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 23:01:32 2024 UTC