Bug #66325 [NEW]: is_array argument is not passed by reference

From: Date: Thu, 19 Dec 2013 18:01:20 +0000
Subject: Bug #66325 [NEW]: is_array argument is not passed by reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183402@lists.php.net to get a copy of this message
From: ujvari at microsec dot hu Operating system: PHP version: Irrelevant Package: Arrays related Bug Type: Bug Bug description:is_array argument is not passed by reference Description: ------------ The is_array() function does not takes it's argument by reference, but copies it. When it takes a large array as an argument and it is called this way many times (for example in a "for" cycle) then it can take a huge time to run beacause of large amount of memory copies. The same problem probably exists at other array related functions. In PHP 5.3 and earlier you cound use is_array(&$array) to mitigate the performance bottleneck. Since call-time pass-by-reference was removed in PHP 5.4 there is no way to do a workaround anymore. Test script: --------------- <?php function delta($prefix, $t1) { $t2 = microtime(true); printf("%s %0.6f\n", $prefix, ($t2 - $t1) * 1000); } function &genarray() { $a = array(); for($i = 0; $i < 10000; $i++) { $a[] = $i; } return($a); } function noref(&$a) { for($i = 0; $i < 10000; $i++) { is_array($a); } } function byref(&$a) { for($i = 0; $i < 10000; $i++) { is_array(&$a); } } $a = &genarray(); $t1 = microtime(true); noref($a); delta("NoRef:", $t1); $t3 = microtime(true); byref($a); delta("ByRef:", $t3); ?> Expected result: ---------------- I expected that NoRef timing be (almost) equal to ByRef timing. Actual result: -------------- NoRef: 9246.673107 ByRef: 1.910925 NoRef is ~5000 times slower than ByRef. -- Edit bug report at https://bugs.php.net/bug.php?id=66325&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66325&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66325&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66325&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66325&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66325&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66325&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66325&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66325&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66325&r=support Expected behavior: https://bugs.php.net/fix.php?id=66325&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66325&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66325&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66325&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66325&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66325&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66325&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66325&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66325&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66325&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66325&r=mysqlcfg

« previous php.bugs (#183402) next »