#41686 [Opn->Csd]: Omitting length param in array_slice not possible

From: Date: Mon, 18 Jun 2007 16:53:25 +0000
Subject: #41686 [Opn->Csd]: Omitting length param in array_slice not possible
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-113904@lists.php.net to get a copy of this message
ID: 41686 Updated by: iliaa@php.net Reported By: rele at gmx dot de -Status: Open +Status: Closed Bug Type: Scripting Engine problem Operating System: Windows XP SP2 PHP Version: 5.2.3 New Comment: This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2007-06-14 15:14:20] rele at gmx dot de I could reproduce the same result with PHP 5.2.1 on SuSE Linux Enterprise Server 9. ------------------------------------------------------------------------ [2007-06-14 10:10:31] rele at gmx dot de 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 this bug report at http://bugs.php.net/?id=41686&edit=1

« previous php.bugs (#113904) next »