|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-10-19 10:43 UTC] jani@php.net
[2009-12-08 11:55 UTC] felipe@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 22:00:01 2025 UTC |
Description: ------------ In an attempt to cull some unneeded array elements from within a user-defined function for uksort(), I came across a very odd memory exhaustion issue where array.c collapses under a sudden 1.5GB memory allocation attempt. I realize this may not be the best way to accomplish my goal, but am pretty sure the memory exhaustion shouldn't be happening, regardless. Reproduce code: --------------- <?php $sortOrder = Array(281, 830, 580, 541, 838, 839, 702, 625, 102, 234, 532, 317, 859, 738, 17, 350); $myArray = Array( 830 => 'eightthirty', 317 => 'threeseventeen', 102 => 'oneohtwo', 281 => 'twoeightyone', 14 => 'fourteen', 580 => 'fiveeighty', 541 => 'fivefourtyone', 350 => 'threefifty', 838 => 'eightthirtyeight', 839 => 'eightthirtynine', 702 => 'sevenohtwo', 625 => 'sixtwentyfive', 234 => 'twothreefour', 532 => 'fivethirtytwo', 859 => 'eightfiftynine', 738 => 'seventhirtyeight', 17 => 'seventeen' ); function sortByOrder($a, $b) { global $sortOrder; global $myArray; if (!in_array($a, $sortOrder)) { unset($myArray[$a]); return 1; } if (!in_array($b, $sortOrder)) { return -1; } return array_search($a, $sortOrder) - array_search($b, $sortOrder); } uksort($myArray, 'sortByOrder'); print_r($myArray); ?> Expected result: ---------------- Expected result is an array sorted to match $sortOrder Actual result: -------------- Fatal error: Allowed memory size of 16777216 bytes exhausted at /root/source/php-5.3.0/ext/standard/array.c:694 (tried to allocate 1515870810 bytes) in /path/to/uksort_memory.php on line 38