php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74270 T_ENCAPSED_AND_WHITESPACE Error Implies an Error in the Interpreter
Submitted: 2017-03-19 00:11 UTC Modified: 2021-01-15 15:29 UTC
From: mark at manngo dot net Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: Any
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: mark at manngo dot net
New email:
PHP Version: OS:

 

 [2017-03-19 00:11 UTC] mark at manngo dot net
Description:
------------
It is a well know issue that a string like "Something $array['key'] etc" will produce the notorious T_ENCAPSED_AND_WHITESPACE error. The only way around it is to remove the inner quotes or to enclose the variable expression in braces.

Apart from the fact that the error code is unintelligible to most normal human beings, the source of the error indicates a mis-interpretation in the handling of the string.

I have sought the advice of Eric Wastl, who has added it to his list (http://phpsadness.com/sad/54). In his email to me:

”After tearing this one apart for a while, I'm pretty sure it's an edgecase bug in the tokenizer.  It's existed for a long time, and it's still there in 7.10.”

Adding my own interpretation, it appears that having a real string literal inside a string literal appears to be causing a problem, and PHP’s flexibility in handling single or double quotes appear to be its undoing at this point. But that’s just looking at the problem from the outside.

I cannot see how producing this type of error is intended behaviour, since it is a natural expectation that the above string is correct.

I therefore submit it as a bug.

Please note that although the bug database contains a number of references to T_ENCAPSED_AND_WHITESPACE, none actually submit the error as a bug in PHP, and none appear to be resolved.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-24 23:18 UTC] kalle@php.net
-Package: Strings related +Package: Scripting Engine problem
 [2021-01-15 15:29 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-01-15 15:29 UTC] cmb@php.net
The current behavior is documented in the PHP manual[1], so this
is not a bug.  Also note that the manual states:

| For anything more complex, you should use the complex syntax.

If you feel strongly that the existing behavior should be changed,
please pursue the RFC process[2].

[1] <https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing>
[2] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC