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;
}
/* 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;
}
--- /dev/null
+--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