summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJani Taskinen <jani@php.net>2007-11-02 10:50:33 +0000
committerJani Taskinen <jani@php.net>2007-11-02 10:50:33 +0000
commit231fcedd035363988cfb6629ddd2c2615e6557d8 (patch)
tree8b2f9644b77297de0f68fbf41caed225f4c7a74f
parent860fd6fd2bf5094231fb69a6c9f0b1a4ec953ed6 (diff)
downloadphp-git-231fcedd035363988cfb6629ddd2c2615e6557d8.tar.gz
MFB52: Fixed bug #41686
-rw-r--r--ext/standard/array.c6
-rw-r--r--ext/standard/tests/array/bug41686.phpt94
2 files changed, 97 insertions, 3 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index f0423ccb9e..f72f8aed61 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2309,7 +2309,7 @@ PHP_FUNCTION(array_slice)
ulong num_key;
HashPosition hpos;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|lb", &input,
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|l!b", &input,
&offset, &length, &preserve_keys) == FAILURE) {
return;
}
@@ -2317,8 +2317,8 @@ PHP_FUNCTION(array_slice)
/* Get number of entries in the input hash */
num_in = zend_hash_num_elements(Z_ARRVAL_P(input));
- /* We want all entries from offset to the end if length is not passed */
- if (ZEND_NUM_ARGS() < 3) {
+ /* We want all entries from offset to the end if length is not passed or length is null */
+ if (ZEND_NUM_ARGS() < 3 || length == NULL) {
length = num_in;
}
diff --git a/ext/standard/tests/array/bug41686.phpt b/ext/standard/tests/array/bug41686.phpt
new file mode 100644
index 0000000000..74863f0d66
--- /dev/null
+++ b/ext/standard/tests/array/bug41686.phpt
@@ -0,0 +1,94 @@
+--TEST--
+Bug #41686 (Omitting length param in array_slice not possible)
+--FILE--
+<?php
+$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)
+);
+
+echo "Done\n";
+?>
+--EXPECT--
+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)
+}
+Done
+--UEXPECT--
+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) {
+ [u"b"]=>
+ int(1)
+ [u"c"]=>
+ int(2)
+}
+array(2) {
+ [u"b"]=>
+ int(1)
+ [u"c"]=>
+ int(2)
+}
+array(2) {
+ [u"b"]=>
+ int(1)
+ [u"c"]=>
+ int(2)
+}
+Done