mirror of
https://github.com/php/php-src.git
synced 2024-12-25 09:49:08 +08:00
Fix handling of double keys in array_column
Also fix resource test to not localize __FILE__ to cwd.
This commit is contained in:
parent
b119836765
commit
7b34324f84
@ -2547,6 +2547,9 @@ PHP_FUNCTION(array_column)
|
||||
case IS_LONG:
|
||||
column_idx = Z_LVAL_PP(zcolumn);
|
||||
break;
|
||||
case IS_DOUBLE:
|
||||
column_idx = (long)Z_DVAL_PP(zcolumn);
|
||||
break;
|
||||
case IS_STRING:
|
||||
column = Z_STRVAL_PP(zcolumn);
|
||||
column_len = Z_STRLEN_PP(zcolumn);
|
||||
@ -2569,6 +2572,9 @@ PHP_FUNCTION(array_column)
|
||||
case IS_LONG:
|
||||
key_idx = Z_LVAL_PP(zkey);
|
||||
break;
|
||||
case IS_DOUBLE:
|
||||
key_idx = (long)Z_DVAL_PP(zkey);
|
||||
break;
|
||||
case IS_STRING:
|
||||
key = Z_STRVAL_PP(zkey);
|
||||
key_len = Z_STRLEN_PP(zkey);
|
||||
|
@ -42,8 +42,7 @@ echo "-- last_name column from recordset, keyed by value from first_name column
|
||||
var_dump(array_column($records, 'last_name', 'first_name'));
|
||||
|
||||
echo "\n*** Testing multiple data types ***\n";
|
||||
$file = basename(__FILE__);
|
||||
$fh = fopen($file, 'r', true);
|
||||
$fh = fopen(__FILE__, 'r', true);
|
||||
$values = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
@ -89,11 +88,13 @@ $numericCols = array(
|
||||
);
|
||||
var_dump(array_column($numericCols, 1));
|
||||
var_dump(array_column($numericCols, 1, 0));
|
||||
var_dump(array_column($numericCols, 1, 0.123));
|
||||
|
||||
echo "\n*** Testing failure to find specified column ***\n";
|
||||
var_dump(array_column($numericCols, 2));
|
||||
var_dump(array_column($numericCols, 'foo'));
|
||||
var_dump(array_column($numericCols, 0, 'foo'));
|
||||
var_dump(array_column($numericCols, 3.14));
|
||||
|
||||
echo "\n*** Testing single dimensional array ***\n";
|
||||
$singleDimension = array('foo', 'bar', 'baz');
|
||||
@ -230,6 +231,14 @@ array(3) {
|
||||
["ccc"]=>
|
||||
string(3) "333"
|
||||
}
|
||||
array(3) {
|
||||
["aaa"]=>
|
||||
string(3) "111"
|
||||
["bbb"]=>
|
||||
string(3) "222"
|
||||
["ccc"]=>
|
||||
string(3) "333"
|
||||
}
|
||||
|
||||
*** Testing failure to find specified column ***
|
||||
array(0) {
|
||||
@ -244,6 +253,8 @@ array(3) {
|
||||
[2]=>
|
||||
string(3) "ccc"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
|
||||
*** Testing single dimensional array ***
|
||||
array(0) {
|
||||
|
@ -26,18 +26,12 @@ var_dump(array_column(1, 'foo'));
|
||||
echo "\n-- Testing array_column() column key parameter should be a string or an integer (testing bool) --\n";
|
||||
var_dump(array_column(array(), true));
|
||||
|
||||
echo "\n-- Testing array_column() column key parameter should be a string or integer (testing float) --\n";
|
||||
var_dump(array_column(array(), 2.3));
|
||||
|
||||
echo "\n-- Testing array_column() column key parameter should be a string or integer (testing array) --\n";
|
||||
var_dump(array_column(array(), array()));
|
||||
|
||||
echo "\n-- Testing array_column() index key parameter should be a string or an integer (testing bool) --\n";
|
||||
var_dump(array_column(array(), 'foo', true));
|
||||
|
||||
echo "\n-- Testing array_column() index key parameter should be a string or integer (testing float) --\n";
|
||||
var_dump(array_column(array(), 'foo', 2.3));
|
||||
|
||||
echo "\n-- Testing array_column() index key parameter should be a string or integer (testing array) --\n";
|
||||
var_dump(array_column(array(), 'foo', array()));
|
||||
|
||||
@ -71,11 +65,6 @@ NULL
|
||||
Warning: array_column(): The column key should be either a string or an integer in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing array_column() column key parameter should be a string or integer (testing float) --
|
||||
|
||||
Warning: array_column(): The column key should be either a string or an integer in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing array_column() column key parameter should be a string or integer (testing array) --
|
||||
|
||||
Warning: array_column(): The column key should be either a string or an integer in %s on line %d
|
||||
@ -86,11 +75,6 @@ bool(false)
|
||||
Warning: array_column(): The index key should be either a string or an integer in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing array_column() index key parameter should be a string or integer (testing float) --
|
||||
|
||||
Warning: array_column(): The index key should be either a string or an integer in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing array_column() index key parameter should be a string or integer (testing array) --
|
||||
|
||||
Warning: array_column(): The index key should be either a string or an integer in %s on line %d
|
||||
|
Loading…
Reference in New Issue
Block a user