Skip to content

Commit

Permalink
Fix handling of double keys in array_column
Browse files Browse the repository at this point in the history
Also fix resource test to not localize __FILE__ to cwd.
  • Loading branch information
sgolemon committed Apr 22, 2013
1 parent b119836 commit 7b34324
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
6 changes: 6 additions & 0 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions ext/standard/tests/array/array_column_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand All @@ -244,6 +253,8 @@ array(3) {
[2]=>
string(3) "ccc"
}
array(0) {
}

*** Testing single dimensional array ***
array(0) {
Expand Down
16 changes: 0 additions & 16 deletions ext/standard/tests/array/array_column_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7b34324

Please sign in to comment.