From: y_kopel at walla dot com Operating system: linux PHP version: 5.3.1 PHP Bug Type: Arrays related Bug description: the iteration on arrays with calling functions is very slow
Description: ------------ the iteration on arrays with calling functions is very slow comparing php 5.2.1 to 5.3.1 Reproduce code: --------------- <?php define("FLOATING_POINT",6); function ww($f){ echo sprintf("%.".FLOATING_POINT."f", $f)."\n"; } class A{ protected $users; function __construct(){ for ($i = 0 ;$i < 100000 ; $i++){ $this->users[$i]['ELEMENT'] = array("a","b"); $this->users[$i]['SUM'] = 2; } } function check_more_than_one_element(){ $sum = 0; foreach ($this->users as &$u){ if (count($u['ELEMENT']) > 1){ $sum++; } } return $sum; } function a_check_more_than_one_element(){ $sum = 0; foreach ($this->users as &$u){ if ($u['SUM'] > 1){ $sum++; } } return $sum; } } $a = new A(); $start = microtime(true); echo "-----\n"; for ($i = 0 ;$i < 5 ; $i++){ $a->check_more_than_one_element(); $a->check_more_than_one_element(); $a->check_more_than_one_element(); $a->check_more_than_one_element(); } echo "-----\n"; echo microtime(true) - $start."\n"; $a = new A(); $start = microtime(true); echo "-----\n"; for ($i = 0 ;$i < 5 ; $i++){ $a->a_check_more_than_one_element(); $a->a_check_more_than_one_element(); $a->a_check_more_than_one_element(); $a->a_check_more_than_one_element(); } echo "-----\n"; echo microtime(true) - $start."\n"; ?> Expected result: ---------------- php 5.2.1 ========= ----- ----- 1.75261092186 ----- ----- 1.05390191078 Actual result: -------------- php 5.3.1 ========= ----- ----- 58.992564916611 ----- ----- 30.829360961914 -- Edit bug report at http://bugs.php.net/?id=51122&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51122&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51122&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51122&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51122&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51122&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51122&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51122&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51122&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51122&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51122&r=support Expected behavior: http://bugs.php.net/fix.php?id=51122&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51122&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51122&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51122&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51122&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51122&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51122&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51122&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51122&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51122&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51122&r=mysqlcfg