Skip to content

Promote warnings to errors in array_column() #4581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -4131,7 +4131,7 @@ zend_bool array_column_param_helper(zval *param,
return 1;

default:
php_error_docref(NULL, E_WARNING, "The %s key should be either a string or an integer", name);
zend_type_error("The %s key should be either a string or an integer", name);
return 0;
}
}
Expand Down Expand Up @@ -4194,7 +4194,7 @@ PHP_FUNCTION(array_column)

if ((column && !array_column_param_helper(column, "column")) ||
(index && !array_column_param_helper(index, "index"))) {
RETURN_FALSE;
return;
}

array_init_size(return_value, zend_hash_num_elements(input));
Expand Down
48 changes: 29 additions & 19 deletions ext/standard/tests/array/array_column_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,51 @@ Test array_column() function: error conditions
*/

echo "*** Testing array_column() : error conditions ***\n";

echo "\n-- Testing array_column() column key parameter should be a string or an integer (testing bool) --\n";
var_dump(array_column(array(), true));
try {
var_dump(array_column(array(), true));
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}


echo "\n-- Testing array_column() column key parameter should be a string or integer (testing array) --\n";
var_dump(array_column(array(), array()));
try {
var_dump(array_column(array(), array()));
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}

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));
try {
var_dump(array_column(array(), 'foo', true));
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}

echo "\n-- Testing array_column() index key parameter should be a string or integer (testing array) --\n";
var_dump(array_column(array(), 'foo', array()));
try {
var_dump(array_column(array(), 'foo', array()));
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}

echo "Done\n";
?>
--EXPECTF--

DONE
--EXPECT--
*** Testing array_column() : error conditions ***

-- Testing array_column() column key parameter should be a string or an integer (testing bool) --

Warning: array_column(): The column key should be either a string or an integer in %s on line %d
bool(false)
The column key should be either a string or an integer

-- 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
bool(false)
The column key should be either a string or an integer

-- Testing array_column() index key parameter should be a string or an integer (testing bool) --

Warning: array_column(): The index key should be either a string or an integer in %s on line %d
bool(false)
The index key should be either a string or an integer

-- Testing array_column() index key parameter should be a string or integer (testing array) --
The index key should be either a string or an integer

Warning: array_column(): The index key should be either a string or an integer in %s on line %d
bool(false)
Done
DONE