From: Jani Taskinen Date: Fri, 2 Nov 2007 10:50:33 +0000 (+0000) Subject: MFB52: Fixed bug #41686 X-Git-Tag: RELEASE_2_0_0a1~1490 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=231fcedd035363988cfb6629ddd2c2615e6557d8;p=php MFB52: Fixed bug #41686 --- 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-- +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