jani Tue Dec 11 09:47:21 2007 UTC
Added files: (Branch: PHP_5_3)
/php-src/ext/standard/tests/array bug43541.phpt
Modified files:
/php-src/ext/standard array.c
/php-src/ext/standard/tests/array array_slice.phpt
Log:
MFH: - Fixed bug #43541
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.308.2.21.2.37.2.11&r2=1.308.2.21.2.37.2.12&diff_format=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.308.2.21.2.37.2.11
php-src/ext/standard/array.c:1.308.2.21.2.37.2.12
--- php-src/ext/standard/array.c:1.308.2.21.2.37.2.11 Wed Dec 5 19:55:31 2007
+++ php-src/ext/standard/array.c Tue Dec 11 09:47:20 2007
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.308.2.21.2.37.2.11 2007/12/05 19:55:31 iliaa Exp $ */
+/* $Id: array.c,v 1.308.2.21.2.37.2.12 2007/12/11 09:47:20 jani Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -2101,17 +2101,16 @@
zval *input, /* Input array */
**entry; /* An array entry */
long offset, /* Offset to get elements from */
- length; /* How many elements to get */
+ length = 0; /* How many elements to get */
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 *length_param;
char *string_key;
uint string_key_len;
ulong num_key;
HashPosition hpos;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|zb", &input,
&offset, &length_param, &preserve_keys) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|lb", &input,
&offset, &length, &preserve_keys) == FAILURE) {
return;
}
@@ -2119,12 +2118,10 @@
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(length_param) != IS_NULL) {
- length = Z_LVAL_P(length_param);
- } else {
+ if (length == 0) {
length = num_in;
}
-
+
/* Initialize returned array */
array_init(return_value);
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_slice.phpt?r1=1.2.2.2&r2=1.2.2.3&diff_format=u
Index: php-src/ext/standard/tests/array/array_slice.phpt
diff -u php-src/ext/standard/tests/array/array_slice.phpt:1.2.2.2
php-src/ext/standard/tests/array/array_slice.phpt:1.2.2.3
--- php-src/ext/standard/tests/array/array_slice.phpt:1.2.2.2 Fri Nov 2
19:41:11 2007
+++ php-src/ext/standard/tests/array/array_slice.phpt Tue Dec 11 09:47:20 2007
@@ -1,7 +1,6 @@
--TEST--
Testing array_slice() function
--FILE--
-
<?php
$var_array = array(
@@ -89,27 +88,26 @@
var_dump (array_slice($var_array[2], -3, -2, false) );
?>
-
--EXPECTF--
*** Output for Zero Argument ***
-Warning: array_slice() expects at least %d parameters, %d given in %s on line
%d
+Warning: array_slice() expects at least 2 parameters, 0 given in %s on line %d
*** Output for Single array Argument ***
-Warning: array_slice() expects at least %d parameters, %d given in %s on line
%d
+Warning: array_slice() expects at least 2 parameters, 1 given in %s on line %d
*** Output for invalid number of Arguments ***
-Warning: array_slice() expects at most %d parameters, %d given in %s on line %d
+Warning: array_slice() expects at most 4 parameters, 5 given in %s on line %d
*** Output for scalar Argument ***
-Warning: array_slice() expects parameter %d to be array, integer given in %s
on line %d
+Warning: array_slice() expects parameter 1 to be array, integer given in %s on
line %d
*** Output for string Argument ***
-Warning: array_slice() expects parameter %d to be array, string given in %s on
line %d%d
+Warning: array_slice() expects parameter 1 to be array, string given in %s on
line %d
*** Iteration 1 ***
@@ -218,7 +216,23 @@
[2]=>
int(4)
}
-array(0) {
+array(8) {
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+ [2]=>
+ int(4)
+ [3]=>
+ int(5)
+ [4]=>
+ int(6)
+ [5]=>
+ int(7)
+ [6]=>
+ int(8)
+ [7]=>
+ int(9)
}
array(5) {
[0]=>
@@ -240,7 +254,25 @@
[2]=>
int(3)
}
-array(0) {
+array(9) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ [3]=>
+ int(4)
+ [4]=>
+ int(5)
+ [5]=>
+ int(6)
+ [6]=>
+ int(7)
+ [7]=>
+ int(8)
+ [8]=>
+ int(9)
}
array(6) {
[0]=>
@@ -262,7 +294,11 @@
[1]=>
int(9)
}
-array(0) {
+array(2) {
+ [0]=>
+ int(8)
+ [1]=>
+ int(9)
}
array(0) {
}
@@ -276,7 +312,23 @@
[3]=>
int(4)
}
-array(0) {
+array(8) {
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ [3]=>
+ int(4)
+ [4]=>
+ int(5)
+ [5]=>
+ int(6)
+ [6]=>
+ int(7)
+ [7]=>
+ int(8)
+ [8]=>
+ int(9)
}
array(5) {
[1]=>
@@ -298,7 +350,25 @@
[2]=>
int(3)
}
-array(0) {
+array(9) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ [3]=>
+ int(4)
+ [4]=>
+ int(5)
+ [5]=>
+ int(6)
+ [6]=>
+ int(7)
+ [7]=>
+ int(8)
+ [8]=>
+ int(9)
}
array(6) {
[0]=>
@@ -320,7 +390,11 @@
[8]=>
int(9)
}
-array(0) {
+array(2) {
+ [7]=>
+ int(8)
+ [8]=>
+ int(9)
}
array(0) {
}
@@ -366,7 +440,15 @@
[2]=>
string(4) "Four"
}
-array(0) {
+array(4) {
+ [0]=>
+ string(3) "Two"
+ [1]=>
+ string(5) "Three"
+ [2]=>
+ string(4) "Four"
+ [3]=>
+ string(4) "Five"
}
array(1) {
[0]=>
@@ -380,7 +462,17 @@
[2]=>
string(5) "Three"
}
-array(0) {
+array(5) {
+ [0]=>
+ string(3) "One"
+ [1]=>
+ string(3) "Two"
+ [2]=>
+ string(5) "Three"
+ [3]=>
+ string(4) "Four"
+ [4]=>
+ string(4) "Five"
}
array(2) {
[0]=>
@@ -394,7 +486,11 @@
[1]=>
string(4) "Five"
}
-array(0) {
+array(2) {
+ [0]=>
+ string(4) "Four"
+ [1]=>
+ string(4) "Five"
}
array(0) {
}
@@ -408,7 +504,15 @@
[3]=>
string(4) "Four"
}
-array(0) {
+array(4) {
+ [1]=>
+ string(3) "Two"
+ [2]=>
+ string(5) "Three"
+ [3]=>
+ string(4) "Four"
+ [4]=>
+ string(4) "Five"
}
array(1) {
[1]=>
@@ -422,7 +526,17 @@
[2]=>
string(5) "Three"
}
-array(0) {
+array(5) {
+ [0]=>
+ string(3) "One"
+ [1]=>
+ string(3) "Two"
+ [2]=>
+ string(5) "Three"
+ [3]=>
+ string(4) "Four"
+ [4]=>
+ string(4) "Five"
}
array(2) {
[0]=>
@@ -436,7 +550,11 @@
[4]=>
string(4) "Five"
}
-array(0) {
+array(2) {
+ [3]=>
+ string(4) "Four"
+ [4]=>
+ string(4) "Five"
}
array(0) {
}
@@ -494,7 +612,21 @@
[2]=>
string(5) "seven"
}
-array(0) {
+array(7) {
+ [0]=>
+ string(3) "six"
+ [1]=>
+ int(7)
+ [2]=>
+ string(5) "seven"
+ [3]=>
+ int(8)
+ [4]=>
+ string(5) "eight"
+ [5]=>
+ int(9)
+ [6]=>
+ string(4) "nine"
}
array(4) {
[0]=>
@@ -514,7 +646,23 @@
[2]=>
int(7)
}
-array(0) {
+array(8) {
+ [0]=>
+ int(6)
+ [1]=>
+ string(3) "six"
+ [2]=>
+ int(7)
+ [3]=>
+ string(5) "seven"
+ [4]=>
+ int(8)
+ [5]=>
+ string(5) "eight"
+ [6]=>
+ int(9)
+ [7]=>
+ string(4) "nine"
}
array(5) {
[0]=>
@@ -534,7 +682,11 @@
[1]=>
string(4) "nine"
}
-array(0) {
+array(2) {
+ [0]=>
+ int(9)
+ [1]=>
+ string(4) "nine"
}
array(0) {
}
@@ -548,7 +700,21 @@
[3]=>
string(5) "seven"
}
-array(0) {
+array(7) {
+ [1]=>
+ string(3) "six"
+ [2]=>
+ int(7)
+ [3]=>
+ string(5) "seven"
+ [4]=>
+ int(8)
+ [5]=>
+ string(5) "eight"
+ [6]=>
+ int(9)
+ [7]=>
+ string(4) "nine"
}
array(4) {
[1]=>
@@ -568,7 +734,23 @@
[2]=>
int(7)
}
-array(0) {
+array(8) {
+ [0]=>
+ int(6)
+ [1]=>
+ string(3) "six"
+ [2]=>
+ int(7)
+ [3]=>
+ string(5) "seven"
+ [4]=>
+ int(8)
+ [5]=>
+ string(5) "eight"
+ [6]=>
+ int(9)
+ [7]=>
+ string(4) "nine"
}
array(5) {
[0]=>
@@ -588,7 +770,11 @@
[7]=>
string(4) "nine"
}
-array(0) {
+array(2) {
+ [6]=>
+ int(9)
+ [7]=>
+ string(4) "nine"
}
array(0) {
}
@@ -634,7 +820,15 @@
["d"]=>
string(3) "ddd"
}
-array(0) {
+array(4) {
+ ["A"]=>
+ string(3) "AAA"
+ ["c"]=>
+ string(3) "ccc"
+ ["d"]=>
+ string(3) "ddd"
+ ["e"]=>
+ string(3) "eee"
}
array(1) {
["A"]=>
@@ -648,7 +842,17 @@
["c"]=>
string(3) "ccc"
}
-array(0) {
+array(5) {
+ ["a"]=>
+ string(3) "aaa"
+ ["A"]=>
+ string(3) "AAA"
+ ["c"]=>
+ string(3) "ccc"
+ ["d"]=>
+ string(3) "ddd"
+ ["e"]=>
+ string(3) "eee"
}
array(2) {
["a"]=>
@@ -662,7 +866,11 @@
["e"]=>
string(3) "eee"
}
-array(0) {
+array(2) {
+ ["d"]=>
+ string(3) "ddd"
+ ["e"]=>
+ string(3) "eee"
}
array(0) {
}
@@ -676,8 +884,16 @@
["d"]=>
string(3) "ddd"
}
-array(0) {
-}
+array(4) {
+ ["A"]=>
+ string(3) "AAA"
+ ["c"]=>
+ string(3) "ccc"
+ ["d"]=>
+ string(3) "ddd"
+ ["e"]=>
+ string(3) "eee"
+}
array(1) {
["A"]=>
string(3) "AAA"
@@ -690,7 +906,17 @@
["c"]=>
string(3) "ccc"
}
-array(0) {
+array(5) {
+ ["a"]=>
+ string(3) "aaa"
+ ["A"]=>
+ string(3) "AAA"
+ ["c"]=>
+ string(3) "ccc"
+ ["d"]=>
+ string(3) "ddd"
+ ["e"]=>
+ string(3) "eee"
}
array(2) {
["a"]=>
@@ -704,7 +930,11 @@
["e"]=>
string(3) "eee"
}
-array(0) {
+array(2) {
+ ["d"]=>
+ string(3) "ddd"
+ ["e"]=>
+ string(3) "eee"
}
array(0) {
}
@@ -750,7 +980,15 @@
[2]=>
string(4) "four"
}
-array(0) {
+array(4) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "four"
+ [3]=>
+ string(4) "five"
}
array(1) {
[0]=>
@@ -764,7 +1002,17 @@
[2]=>
string(5) "three"
}
-array(0) {
+array(5) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+ [3]=>
+ string(4) "four"
+ [4]=>
+ string(4) "five"
}
array(2) {
[0]=>
@@ -778,7 +1026,11 @@
[1]=>
string(4) "five"
}
-array(0) {
+array(2) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(4) "five"
}
array(0) {
}
@@ -792,7 +1044,15 @@
[4]=>
string(4) "four"
}
-array(0) {
+array(4) {
+ [2]=>
+ string(3) "two"
+ [3]=>
+ string(5) "three"
+ [4]=>
+ string(4) "four"
+ [5]=>
+ string(4) "five"
}
array(1) {
[2]=>
@@ -806,7 +1066,17 @@
[3]=>
string(5) "three"
}
-array(0) {
+array(5) {
+ [1]=>
+ string(3) "one"
+ [2]=>
+ string(3) "two"
+ [3]=>
+ string(5) "three"
+ [4]=>
+ string(4) "four"
+ [5]=>
+ string(4) "five"
}
array(2) {
[1]=>
@@ -820,7 +1090,11 @@
[5]=>
string(4) "five"
}
-array(0) {
+array(2) {
+ [4]=>
+ string(4) "four"
+ [5]=>
+ string(4) "five"
}
array(0) {
}
@@ -866,7 +1140,15 @@
[2]=>
string(4) "four"
}
-array(0) {
+array(4) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ int(7)
+ [2]=>
+ string(4) "four"
+ [3]=>
+ string(4) "five"
}
array(1) {
[0]=>
@@ -880,7 +1162,17 @@
[2]=>
int(7)
}
-array(0) {
+array(5) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ int(7)
+ [3]=>
+ string(4) "four"
+ [4]=>
+ string(4) "five"
}
array(2) {
[0]=>
@@ -894,7 +1186,11 @@
[1]=>
string(4) "five"
}
-array(0) {
+array(2) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(4) "five"
}
array(0) {
}
@@ -908,7 +1204,15 @@
[4]=>
string(4) "four"
}
-array(0) {
+array(4) {
+ [2]=>
+ string(3) "two"
+ [3]=>
+ int(7)
+ [4]=>
+ string(4) "four"
+ [5]=>
+ string(4) "five"
}
array(1) {
[2]=>
@@ -922,7 +1226,17 @@
[3]=>
int(7)
}
-array(0) {
+array(5) {
+ [1]=>
+ string(3) "one"
+ [2]=>
+ string(3) "two"
+ [3]=>
+ int(7)
+ [4]=>
+ string(4) "four"
+ [5]=>
+ string(4) "five"
}
array(2) {
[1]=>
@@ -936,7 +1250,11 @@
[5]=>
string(4) "five"
}
-array(0) {
+array(2) {
+ [4]=>
+ string(4) "four"
+ [5]=>
+ string(4) "five"
}
array(0) {
}
@@ -1002,7 +1320,25 @@
[""]=>
string(5) "blank"
}
-array(0) {
+array(9) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ int(6)
+ [""]=>
+ string(5) "blank"
+ [2]=>
+ string(5) "float"
+ ["F"]=>
+ string(3) "FFF"
+ ["blank"]=>
+ string(0) ""
+ [3]=>
+ float(3.7)
+ [4]=>
+ string(4) "Five"
+ [5]=>
+ float(8.6)
}
array(6) {
[0]=>
@@ -1026,7 +1362,27 @@
[1]=>
int(6)
}
-array(0) {
+array(10) {
+ ["f"]=>
+ string(3) "fff"
+ [0]=>
+ string(3) "one"
+ [1]=>
+ int(6)
+ [""]=>
+ string(5) "blank"
+ [2]=>
+ string(5) "float"
+ ["F"]=>
+ string(3) "FFF"
+ ["blank"]=>
+ string(0) ""
+ [3]=>
+ float(3.7)
+ [4]=>
+ string(4) "Five"
+ [5]=>
+ float(8.6)
}
array(7) {
["f"]=>
@@ -1050,7 +1406,11 @@
[1]=>
float(8.6)
}
-array(0) {
+array(2) {
+ [0]=>
+ string(4) "Five"
+ [1]=>
+ float(8.6)
}
array(0) {
}
@@ -1064,7 +1424,25 @@
[""]=>
string(5) "blank"
}
-array(0) {
+array(9) {
+ [1]=>
+ string(3) "one"
+ [4]=>
+ int(6)
+ [""]=>
+ string(5) "blank"
+ [2]=>
+ string(5) "float"
+ ["F"]=>
+ string(3) "FFF"
+ ["blank"]=>
+ string(0) ""
+ [3]=>
+ float(3.7)
+ [5]=>
+ string(4) "Five"
+ [6]=>
+ float(8.6)
}
array(6) {
[1]=>
@@ -1088,7 +1466,27 @@
[4]=>
int(6)
}
-array(0) {
+array(10) {
+ ["f"]=>
+ string(3) "fff"
+ [1]=>
+ string(3) "one"
+ [4]=>
+ int(6)
+ [""]=>
+ string(5) "blank"
+ [2]=>
+ string(5) "float"
+ ["F"]=>
+ string(3) "FFF"
+ ["blank"]=>
+ string(0) ""
+ [3]=>
+ float(3.7)
+ [5]=>
+ string(4) "Five"
+ [6]=>
+ float(8.6)
}
array(7) {
["f"]=>
@@ -1112,7 +1510,11 @@
[6]=>
float(8.6)
}
-array(0) {
+array(2) {
+ [5]=>
+ string(4) "Five"
+ [6]=>
+ float(8.6)
}
array(0) {
}
@@ -1154,7 +1556,13 @@
[2]=>
string(2) "45"
}
-array(0) {
+array(3) {
+ [0]=>
+ string(4) "name"
+ [1]=>
+ string(3) "age"
+ [2]=>
+ string(2) "45"
}
array(0) {
}
@@ -1166,7 +1574,15 @@
[2]=>
string(3) "age"
}
-array(0) {
+array(4) {
+ [0]=>
+ int(12)
+ [1]=>
+ string(4) "name"
+ [2]=>
+ string(3) "age"
+ [3]=>
+ string(2) "45"
}
array(1) {
[0]=>
@@ -1178,7 +1594,11 @@
[1]=>
string(2) "45"
}
-array(0) {
+array(2) {
+ [0]=>
+ string(3) "age"
+ [1]=>
+ string(2) "45"
}
array(0) {
}
@@ -1192,7 +1612,13 @@
[3]=>
string(2) "45"
}
-array(0) {
+array(3) {
+ [1]=>
+ string(4) "name"
+ [2]=>
+ string(3) "age"
+ [3]=>
+ string(2) "45"
}
array(0) {
}
@@ -1204,7 +1630,15 @@
[2]=>
string(3) "age"
}
-array(0) {
+array(4) {
+ [0]=>
+ int(12)
+ [1]=>
+ string(4) "name"
+ [2]=>
+ string(3) "age"
+ [3]=>
+ string(2) "45"
}
array(1) {
[0]=>
@@ -1216,7 +1650,11 @@
[3]=>
string(2) "45"
}
-array(0) {
+array(2) {
+ [2]=>
+ string(3) "age"
+ [3]=>
+ string(2) "45"
}
array(0) {
}
@@ -1307,7 +1745,23 @@
array(0) {
}
}
-array(0) {
+array(2) {
+ [0]=>
+ array(5) {
+ [0]=>
+ int(10)
+ [1]=>
+ int(20)
+ [2]=>
+ int(30)
+ [3]=>
+ int(40)
+ [4]=>
+ int(50)
+ }
+ [1]=>
+ array(0) {
+ }
}
array(0) {
}
@@ -1338,7 +1792,32 @@
array(0) {
}
}
-array(0) {
+array(3) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "oNe"
+ [1]=>
+ string(3) "tWo"
+ [2]=>
+ int(4)
+ }
+ [1]=>
+ array(5) {
+ [0]=>
+ int(10)
+ [1]=>
+ int(20)
+ [2]=>
+ int(30)
+ [3]=>
+ int(40)
+ [4]=>
+ int(50)
+ }
+ [2]=>
+ array(0) {
+ }
}
array(0) {
}
@@ -1360,7 +1839,23 @@
array(0) {
}
}
-array(0) {
+array(2) {
+ [0]=>
+ array(5) {
+ [0]=>
+ int(10)
+ [1]=>
+ int(20)
+ [2]=>
+ int(30)
+ [3]=>
+ int(40)
+ [4]=>
+ int(50)
+ }
+ [1]=>
+ array(0) {
+ }
}
array(0) {
}
@@ -1384,7 +1879,23 @@
array(0) {
}
}
-array(0) {
+array(2) {
+ [1]=>
+ array(5) {
+ [0]=>
+ int(10)
+ [1]=>
+ int(20)
+ [2]=>
+ int(30)
+ [3]=>
+ int(40)
+ [4]=>
+ int(50)
+ }
+ [2]=>
+ array(0) {
+ }
}
array(0) {
}
@@ -1415,7 +1926,32 @@
array(0) {
}
}
-array(0) {
+array(3) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "oNe"
+ [1]=>
+ string(3) "tWo"
+ [2]=>
+ int(4)
+ }
+ [1]=>
+ array(5) {
+ [0]=>
+ int(10)
+ [1]=>
+ int(20)
+ [2]=>
+ int(30)
+ [3]=>
+ int(40)
+ [4]=>
+ int(50)
+ }
+ [2]=>
+ array(0) {
+ }
}
array(0) {
}
@@ -1437,7 +1973,23 @@
array(0) {
}
}
-array(0) {
+array(2) {
+ [1]=>
+ array(5) {
+ [0]=>
+ int(10)
+ [1]=>
+ int(20)
+ [2]=>
+ int(30)
+ [3]=>
+ int(40)
+ [4]=>
+ int(50)
+ }
+ [2]=>
+ array(0) {
+ }
}
array(0) {
}
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/bug43541.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/bug43541.phpt
+++ php-src/ext/standard/tests/array/bug43541.phpt
--TEST--
Bug #43541 (length parameter omitted or not does not work when casted to float)
--FILE--
<?php
$arr = array(1, 2, 3, 4, 5, 6);
var_dump(array_slice($arr, 0, (float)2));
var_dump(array_slice($arr, 0, (int)2));
?>
--EXPECT--
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
--UEXPECT--
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php