|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-11-23 14:01 UTC] mort at dsl dot pipex dot com
When using single quotes (i dont know if they will be allowed to show here) (') inside double quote strings ("), a parse error is produced;
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
This happened on Windows ME, using the latest Apache 1.3, and all settings in php.ini are default.
This is very annoying, please fix it!
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 21:00:01 2025 UTC |
Btw, this happens when you do: print "a foo $bar['blah'] eh"; Don't do that. You can do either: print "a foo {$bar['blah']} eh"; print "a foo $bar[blah] eh"; print "a foo " . $bar['blah'] . " eh"; But when outside of strings always quote your keys: print $bar[blah]; // bad print $bar['blah']; // good Unless of course you defined blah as a constant earlier. Anyway I'm making a faq out of this question and marking as a doc bug because this question comes up a lot especially since 4.1.0 (autoglobals) and 4.2.0 (register_globals default change).As it turns out, the string docs are wrong and contain the following in the example: // This is wrong for the same reason // as $foo[bar] is wrong outside a string. echo "This is wrong: {$arr[foo][3]}"; I'll rewrite this part of the documention too. $foo[bar] is perfectly fine inside strings, CONSTANTS aren't seen in strings. Anyway, this will be further explained with a more specific example too. And a faq entry :) This question comes up waaaaaaay too much these days.Philip, please do not change that part of the documentation. **It is correct!**. Try with this script: <?php error_reporting(E_ALL); ini_set("display_errors", TRUE); $arr['foo'][3] = 14; echo "This is wrong: {$arr[foo][3]}"; echo "This is good: {$arr['foo'][3]}"; ?> For the first echo line, a NOTICE error is echoed out... So the documentation is correct. It may not be clear enough, but it is correct, the example is right.Sort of. This is a feature I was not aware of in PHP and imho is sort of a bug :) As it turns out, constants are only seen in strings if: a) It's an array key b) {braces} are around the array So for example, NO E_NOTICE is generated from "a $arr[foo]" but "a {$arr[foo]}" does! And btw, "a {foo}" does not look for the constant foo. And because multidimensional arrays inside strings require {braces} this is an important point. IMHO this behavior of constants inside strings is inconsistent and I'm writing php-dev now! :)