php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37190 non-local associative arrays are inaccessible
Submitted: 2006-04-25 05:02 UTC Modified: 2006-04-25 06:53 UTC
From: mlandis at pnmx dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.1.2 OS: Fedora Core 4
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mlandis at pnmx dot com
New email:
PHP Version: OS:

 

 [2006-04-25 05:02 UTC] mlandis at pnmx dot com
Description:
------------
Associative array reference, e.g.

    $monIdx = $sti["Mar"];

behaves as expected if array $sti has local scope, but if the line of code above appears within a function and $sti is declared outside the function, you get nothing .



Reproduce code:
---------------
$sti = array( "Jan" =>  1, "Feb" =>  2, "Mar" =>  3,
              "Apr" =>  4, "May" =>  5, "Jun" =>  6,
              "Jul" =>  7, "Aug" =>  8, "Sep" =>  9,
              "Oct" => 10, "Nov" => 11, "Dec" => 12  );
function foobar( $monSt )
{
   return $sti[$monSt];
}
$res = foobar( "May" );
echo "res=$res<br>\r\n";

Expected result:
----------------
res=5<br>\r\n

Actual result:
--------------
res=<br>\r\n

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-25 06:53 UTC] mike@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


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 01:01:35 2025 UTC