php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23532 Associative Array Problem Problem in PHP5 and inconsistency in 4.3.1
Submitted: 2003-05-07 13:17 UTC Modified: 2003-05-08 04:49 UTC
From: mjsabby at yahoo dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5CVS-2003-05-07 (dev) OS: WinNT 5.0 (2K), RHL 7.3
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: mjsabby at yahoo dot com
New email:
PHP Version: OS:

 

 [2003-05-07 13:17 UTC] 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!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-08 04:49 UTC] mgf@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 15:01:33 2024 UTC