com php-src: Make array_slice $length param a nulla ble integer: ext/standard/array.c ext/standard/tests/ array/array_slice_variation1.phpt
ext/standard/tests/ array/array_slice_variation3.phpt
| From: | Nikita Popov | Date: | Mon, 04 Feb 2019 09:38:42 +0000 |
| Subject: | com php-src: Make array_slice $length param a nulla ble integer: ext/standard/array.c ext/standard/tests/ array/array_slice_variation1.phpt ext/standard/tests/ array/array_slice_variation3.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104432@lists.php.net to get a copy of this message | ||
Commit: 0476d558272c18778f95c0368e18108771a63d99
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 4 Feb 2019 10:38:42 +0100
Parents: 623911f993f39ebbe75abe2771fc89faf6b15b9b
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0476d558272c18778f95c0368e18108771a63d99
Log:
Make array_slice $length param a nullable integer
Instead of having custom parameter handling.
Changed paths:
M ext/standard/array.c
M ext/standard/tests/array/array_slice_variation1.phpt
M ext/standard/tests/array/array_slice_variation3.phpt
Diff:
diff --git a/ext/standard/array.c b/ext/standard/array.c
index b84e1e3..b77f711 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -3470,14 +3470,14 @@ PHP_FUNCTION(array_splice)
Returns elements specified by offset and length */
PHP_FUNCTION(array_slice)
{
- zval *input, /* Input array */
- *z_length = NULL, /* How many elements to get */
- *entry; /* An array entry */
- zend_long offset, /* Offset to get elements from */
- length = 0;
- zend_bool preserve_keys = 0; /* Whether to preserve keys while copying to the new array or not */
- int num_in, /* Number of elements in the input array */
- pos; /* Current position in the array */
+ zval *input; /* Input array */
+ zval *entry; /* An array entry */
+ zend_long offset; /* Offset to get elements from */
+ zend_long length = 0; /* How many elements to get */
+ zend_bool length_is_null = 1; /* Whether an explicit length has been omitted */
+ zend_bool preserve_keys = 0; /* Whether to preserve keys while copying to the new array */
+ uint32_t num_in; /* Number of elements in the input array */
+ uint32_t pos; /* Current position in the array */
zend_string *string_key;
zend_ulong num_key;
@@ -3485,7 +3485,7 @@ PHP_FUNCTION(array_slice)
Z_PARAM_ARRAY(input)
Z_PARAM_LONG(offset)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(z_length)
+ Z_PARAM_LONG_EX(length, length_is_null, 1, 0)
Z_PARAM_BOOL(preserve_keys)
ZEND_PARSE_PARAMETERS_END();
@@ -3493,10 +3493,8 @@ PHP_FUNCTION(array_slice)
num_in = zend_hash_num_elements(Z_ARRVAL_P(input));
/* We want all entries from offset to the end if length is not passed or is null */
- if (ZEND_NUM_ARGS() < 3 || Z_TYPE_P(z_length) == IS_NULL) {
+ if (length_is_null) {
length = num_in;
- } else {
- length = zval_get_long(z_length);
}
/* Clamp the offset.. */
diff --git a/ext/standard/tests/array/array_slice_variation1.phpt
b/ext/standard/tests/array/array_slice_variation1.phpt
index 7b6d712..f0c30ba 100644
--- a/ext/standard/tests/array/array_slice_variation1.phpt
+++ b/ext/standard/tests/array/array_slice_variation1.phpt
@@ -20,7 +20,7 @@ var_dump(array_slice(range(1, 3), 0, $a));
var_dump($a);
?>
---EXPECT--
+--EXPECTF--
array(3) {
[0]=>
int(1)
@@ -53,8 +53,10 @@ array(1) {
[2]=>
int(3)
}
-array(0) {
-}
-array(0) {
-}
+
+Warning: array_slice() expects parameter 3 to be int, string given in %s on line %d
+NULL
+
+Warning: array_slice() expects parameter 3 to be int, string given in %s on line %d
+NULL
string(3) "foo"
diff --git a/ext/standard/tests/array/array_slice_variation3.phpt
b/ext/standard/tests/array/array_slice_variation3.phpt
index 6cec0bc..cf01db2 100644
--- a/ext/standard/tests/array/array_slice_variation3.phpt
+++ b/ext/standard/tests/array/array_slice_variation3.phpt
@@ -81,7 +81,7 @@ foreach($inputs as $input) {
echo "Done";
?>
---EXPECT--
+--EXPECTF--
*** Testing array_slice() : usage variations ***
-- Iteration 1 --
@@ -171,28 +171,34 @@ array(0) {
}
-- Iteration 16 --
-array(0) {
-}
+
+Warning: array_slice() expects parameter 3 to be int, string given in %s on line %d
+NULL
-- Iteration 17 --
-array(0) {
-}
+
+Warning: array_slice() expects parameter 3 to be int, string given in %s on line %d
+NULL
-- Iteration 18 --
-array(0) {
-}
+
+Warning: array_slice() expects parameter 3 to be int, array given in %s on line %d
+NULL
-- Iteration 19 --
-array(0) {
-}
+
+Warning: array_slice() expects parameter 3 to be int, string given in %s on line %d
+NULL
-- Iteration 20 --
-array(0) {
-}
+
+Warning: array_slice() expects parameter 3 to be int, string given in %s on line %d
+NULL
-- Iteration 21 --
-array(0) {
-}
+
+Warning: array_slice() expects parameter 3 to be int, string given in %s on line %d
+NULL
-- Iteration 22 --
array(2) {