#23532 [Opn->Bgs]: Associative Array Problem Problem in PHP5 and inconsistency in 4.3.1
ID: 23532
Updated by: mgf@php.net
Reported By: mjsabby at yahoo dot com
-Status: Open
+Status: Bogus
Bug Type: Variables related
Operating System: WinNT 5.0 (2K), RHL 7.3
PHP Version: 5CVS-2003-05-07 (dev)
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Please read the documentation on variable parsing in strings
(http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing),
where this behaviour is fully explained.
Previous Comments:
------------------------------------------------------------------------
[2003-05-07 13:17:17] mjsabby at yahoo dot com
There is a very strange error when using associative array naming
within quotes, have a look here. This is based on the PHP5 May 5th
17:30GMT build.
In PHP 4.3.1
<?php
$arr = array("hello" => "hello world");
echo "$arr['hello']";
?>
The above code does not output any information. The quotes have
something to do with this.
<?php
$arr = array("hello" => "hello world");
echo $arr['hello'];
?>
This above code fragment will print "hello world".
The usage that is consistent always is not using single quotes :
<?php
$arr = array("hello" => "hello world");
echo "$arr[hello]"; // echo $arr[hello]; executes!
?>
The above is still acceptable and does not generate any error. Not even
a notice if it is turned on, so it most likely an output related bug.
Now coming to PHP5!
<?php
$arr = array("hello" => "hello world");
echo "$arr[hello]"; echo $arr[hello]; exectues!
?>
The above code works fine, with and without the quotes.
<?php
$arr = array("hello" => "hello world");
echo "$arr['hello']"; // echo $arr['hello']; executes!
?>
This code does not work if the quotes are present, works when the
quotes are removed!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23532&edit=1
Thread (2 messages)