php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65635 cannot dereference array
Submitted: 2013-09-08 18:57 UTC Modified: 2013-09-08 22:10 UTC
From: TorrAB at Yahoo dot com Assigned:
Status: Not a bug Package: Compile Failure
PHP Version: 5.5.3 OS: Windows XP
Private report: No CVE-ID: None
 [2013-09-08 18:57 UTC] TorrAB at Yahoo dot com
Description:
------------
Parse error: syntax error, unexpected "(T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING).
Apparently, the parser cannot dereference $Apt['Color']. May be linked to bug 23022. But why the <unexpected ">?

Test script:
---------------
<?php
#No error, using intermediate var $Colo:
	forEach ($GLOBALS['Aps'] as $GLOBALS['X'] => $Apt){
		$Colo=$Apt['Color'];
		echo "<div class='row' style=\"background-color: $Colo\">";
		echo '</div>';}

#Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\Apache24\htdocs\GoodBadB.php on line 10:
	forEach ($GLOBALS['Aps'] as $GLOBALS['X'] => $Apt){
		echo "<div class='row' style=\"background-color: $Apt['Color']\">";
#Apparently, the parser cannot dereference $Apt['Color']. May be linked to bug 23022. But why the <unexpected ">?
		echo '</div>';}
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-08 21:31 UTC] cmbecker69 at gmx dot de
> Apparently, the parser cannot dereference $Apt['Color'].

No.  The parser won't just accept this syntax.  See the manual[1]
on how to use array indexes in strings.

IMHO, this is not a bug.

[1]  
<http://www.php.net/manual/en/language.types.string.php#language.types.string.pars
ing.simple>
 [2013-09-08 22:10 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-09-08 22:10 UTC] nikic@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Correct, this is not a bug. In string interpolation use either "... $array[key] ..." or "... {$array['key']} ...".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 13:01:30 2024 UTC