Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.6.0a3

Bug #13165 array_fill() not matching output from V5.3.0-dev.
Submitted: 2008-02-21 05:43 UTC Modified: 2008-02-25 09:17 UTC
From: rquadling Assigned: arpad
Status: Closed Package: PHP_Compat (version 1.6.0a1)
PHP Version: 5.2.5 OS: Windows XP SP2
Roadmaps: 1.6.0a2    
Subscription  


 [2008-02-21 05:43 UTC] rquadling (Richard Quadling)
Description: ------------ Hi. 2 problems with array_fill(). 1 - Some odd characters before the opening <?php 2 - The output of php_compat_array_fill() doesn't match the output array_fill(). The problem is the in most people's eyes PHP is wrong and PEAR is right. See bugs : http://bugs.php.net/bug.php?id=43017 and http://bugs.php.net/bug.php?id=40882 also. The attached patch "corrects" the problem. Richard. Test script: --------------- <?php include 'PHP/Compat/Function/array_fill.php'; print_r(array_fill(-3, 5, 0)); print_r(php_compat_array_fill(-3, 5, 0)); Expected result: ---------------- Array ( [-3] => 0 [-2] => 0 [-1] => 0 [0] => 0 [1] => 0 ) Array ( [-3] => 0 [-2] => 0 [-1] => 0 [0] => 0 [1] => 0 ) Actual result: -------------- | Array ( [-3] => 0 [0] => 0 [1] => 0 [2] => 0 [3] => 0 ) Array ( [-3] => 0 [-2] => 0 [-1] => 0 [0] => 0 [1] => 0 )

Comments

 [2008-02-21 05:46 UTC] rquadling (Richard Quadling)
Argh. Sorry. My expected results are incorrect. They should be ... Array ( [-3] => 0 [0] => 0 [1] => 0 [2] => 0 [3] => 0 ) Array ( [-3] => 0 [0] => 0 [1] => 0 [2] => 0 [3] => 0 ) Which is "wrong", but matches what PHP actually does.
 [2008-02-24 18:36 UTC] arpad (Arpad Ray)
Many thanks for the report Richard, I applied your patch with the slight change that we need to subtract 1 not 2 from the end index when the start index < 0 (because we don't include the end index itself).
 [2008-02-25 07:05 UTC] rquadling (Richard Quadling)
Ah. Yes. Sorry. < not <= in for() loop. Hey. At least you found my (ahem) deliberate (ahem) mistake! What a daft function though.
 [2008-02-25 07:13 UTC] rquadling (Richard Quadling)
As this fix is to emulate PHP4.3.0+, is there a way to say what version of PHP we are trying to provide a compatible function for? For V4.2.* and earlier, the original function is correct (according to the notes on arrays ... "Before PHP 4.3.0, appending to an array in which the current maximum key was negative would create a new key as described above. Since PHP 4.3.0, the new key will be 0." "described above" means 1 more than the highest existing key.
 [2008-02-25 07:18 UTC] rquadling (Richard Quadling)
Hmm, sorry for the noise, but in the Components.php file, the version # for array_fill is 4.2.0. Maybe this should now be 4.3.0. And we would need a different one for emulating v4.2.0
 [2008-02-25 09:17 UTC] arpad (Arpad Ray)
I think if we start providing historical implementations too this will get very messy - I'd much rather just accept the current PHP behaviour as correct and try to make all possible host versions behave like that. Changing the version in Components.php to 4.3.0 should mean that PHP_Compat::loadVersion('4.2.0') wouldn't load it (when it obviously should), the current code does but I'm pretty sure that's in error - I'll check that out in more detail later. What are your thoughts Aidan?