#41686 [NEW]: Omitting length param in array_slice not possible

From: Date: Thu, 14 Jun 2007 10:10:31 +0000
Subject: #41686 [NEW]: Omitting length param in array_slice not possible
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-113773@lists.php.net to get a copy of this message
From: rele at gmx dot de Operating system: Windows XP SP2 PHP version: 5.2.3 PHP Bug Type: Scripting Engine problem Bug description: Omitting length param in array_slice not possible Description: ------------ array_slice supports omitting of the $length parameter only if you pass just the first two parameters (params 1 and 2), but passing the default value NULL when you want to set $preserve_keys to TRUE (params 1, 2, 3 and 4) does not work. This would be especially useful for associative arrays. Reproduce code: --------------- $a = array(1,2,3); $b = array('a'=>1,'b'=>1,'c'=>2); var_dump(array_slice($a, 1), array_slice($a, 1, 2, TRUE), array_slice($a, 1, NULL, TRUE), array_slice($b, 1), array_slice($b, 1, 2, TRUE), array_slice($b, 1, NULL, TRUE)); Expected result: ---------------- array(2) { [0]=> int(2) [1]=> int(3) } array(2) { [1]=> int(2) [2]=> int(3) } array(2) { [1]=> int(2) [2]=> int(3) } array(2) { ["b"]=> int(1) ["c"]=> int(2) } array(2) { ["b"]=> int(1) ["c"]=> int(2) } array(2) { ["b"]=> int(1) ["c"]=> int(2) } Actual result: -------------- array(2) { [0]=> int(2) [1]=> int(3) } array(2) { [1]=> int(2) [2]=> int(3) } array(0) { } array(2) { ["b"]=> int(1) ["c"]=> int(2) } array(2) { ["b"]=> int(1) ["c"]=> int(2) } array(0) { } -- Edit bug report at http://bugs.php.net/?id=41686&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41686&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41686&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41686&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41686&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41686&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41686&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41686&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41686&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41686&r=support Expected behavior: http://bugs.php.net/fix.php?id=41686&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41686&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41686&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41686&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41686&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41686&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41686&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41686&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41686&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41686&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41686&r=mysqlcfg

« previous php.bugs (#113773) next »