com php-src: Promote warnings to errors in array_column() : ext/standard/array.c ext/standard/tests/array/array _column_error.phpt
| From: | George Peter Banyard | Date: | Thu, 22 Aug 2019 17:27:47 +0000 |
| Subject: | com php-src: Promote warnings to errors in array_column() : ext/standard/array.c ext/standard/tests/array/array _column_error.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-107993@lists.php.net to get a copy of this message | ||
Commit: 7dcbcd4ca5bf954f56e28a233215359050041893
Author: George Peter Banyard <girgias@php.net> Wed, 21 Aug 2019 01:52:17 +0200
Parents: cee24be5b3893423fa0abd8d5e15204ff18d1e22
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7dcbcd4ca5bf954f56e28a233215359050041893
Log:
Promote warnings to errors in array_column()
Changed paths:
M ext/standard/array.c
M ext/standard/tests/array/array_column_error.phpt
Diff:
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 164b7da..d37025d 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -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;
}
}
@@ -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));
diff --git a/ext/standard/tests/array/array_column_error.phpt
b/ext/standard/tests/array/array_column_error.phpt
index 9223248..6fb5169 100644
--- a/ext/standard/tests/array/array_column_error.phpt
+++ b/ext/standard/tests/array/array_column_error.phpt
@@ -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