Omitting length param in array_slice not possible
| Bug #41686 | Omitting length param in array_slice not possible | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2007-06-14 10:10 UTC | Modified: | 2007-06-18 16:53 UTC |
|
||||||||||
| From: | rele at gmx dot de | Assigned: | ||||||||||||
| Status: | Closed | Package: | Scripting Engine problem | |||||||||||
| PHP Version: | 5.2.3 | OS: | Windows XP SP2 | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2007-06-14 10:10 UTC] 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) {
}
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2007-06-14 15:14 UTC] rele at gmx dot de
[2007-06-18 16:53 UTC] iliaa@php.net