#30295 [Opn]: array_key_exists() makes a copy of the given array

From: Date: Thu, 30 Sep 2004 23:17:13 +0000
Subject: #30295 [Opn]: array_key_exists() makes a copy of the given array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-66964@lists.php.net to get a copy of this message
ID: 30295 Updated by: helly@php.net Reported By: oliver at burtchen dot com Status: Open Bug Type: Performance problem PHP Version: 5.0.2 New Comment: for a short term solution use array_key_exists($i, &$a); Previous Comments: ------------------------------------------------------------------------ [2004-09-30 23:23:28] oliver at burtchen dot com Description: ------------ it looks loke array_key_exists() makes a copy of the given array if there is a reference to that array. if there is no reference, everything works well. Reproduce code: --------------- // just to get the time in microseconds function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $cnt = 2000; $a = array_fill(0, $cnt, 'foo'); // this works as aspected very fast $mtime = getmicrotime(); for ($i = 0; $cnt > $i; $i++) array_key_exists($i, $a); echo getmicrotime() - $mtime . '<br>'; $b =& $a; // making a reference, but not using it // this will take a huge amount of time, but it's the same code as above $mtime = getmicrotime(); for ($i = 0; $cnt > $i; $i++) array_key_exists($i, $a); echo getmicrotime() - $mtime . '<br>'; Expected result: ---------------- the two loops should work the same. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30295&edit=1

« previous php.bugs (#66964) next »