php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44579 reading non-existing value from multidimentional array
Submitted: 2008-03-31 12:47 UTC Modified: 2008-04-02 09:32 UTC
From: alex at raintree dot ee Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2CVS-2008-03-31 (snap) OS: Windows Server 2003
Private report: No CVE-ID: None
 [2008-03-31 12:47 UTC] alex at raintree dot ee
Description:
------------
Noticed serious performance issues while reading non-existing values from multi-dimensional array. 

Adding ISSET() check before the array read makes the script at least 3 times faster. 

However the main concern is that there are lots of non-optimized scripts that do not have ISSET() around multi-dimensional arrays.



Reproduce code:
---------------
error_reporting(0);

$start = date('H:m:s');

$myArr = array('a');
$test = 'a';

// performance killer loop
for($i = 0; $i < 1000000; $i++)
  if ($myArr[$test][$fieldName] == 5);

/* optimized code
  if (isset($myArr[$test][$fieldName]) && $myArr[$test][$fieldName] == 5) */

$end = date('H:m:s');
echo $start . ' ' . $end;

Expected result:
----------------
I expect the code with ISSET (commented out) run close to as fast as the code without ISSET. 

Actual result:
--------------
Serious performance difference while running code that has ISSET() around multi-dimensional array read vs. code without ISSET().

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-02 09:32 UTC] jani@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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 08:01:35 2024 UTC