Skip to content

Commit 542c342

Browse files
committed
Promote warnings to errors in array_column()
1 parent 5b8e12a commit 542c342

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

ext/standard/array.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4122,14 +4122,15 @@ zend_bool array_column_param_helper(zval *param,
41224122

41234123
case IS_OBJECT:
41244124
if (!try_convert_to_string(param)) {
4125+
zend_type_error("Cannot convert key %s to a string", name);
41254126
return 0;
41264127
}
41274128
/* fallthrough */
41284129
case IS_STRING:
41294130
return 1;
41304131

41314132
default:
4132-
php_error_docref(NULL, E_WARNING, "The %s key should be either a string or an integer", name);
4133+
zend_type_error("The %s key should be either a string or an integer", name);
41334134
return 0;
41344135
}
41354136
}
@@ -4192,6 +4193,7 @@ PHP_FUNCTION(array_column)
41924193

41934194
if ((column && !array_column_param_helper(column, "column")) ||
41944195
(index && !array_column_param_helper(index, "index"))) {
4196+
/* Throw exception ? */
41954197
RETURN_FALSE;
41964198
}
41974199

ext/standard/tests/array/array_column_error.phpt

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,51 @@ Test array_column() function: error conditions
1010
*/
1111

1212
echo "*** Testing array_column() : error conditions ***\n";
13-
1413
echo "\n-- Testing array_column() column key parameter should be a string or an integer (testing bool) --\n";
15-
var_dump(array_column(array(), true));
14+
try {
15+
var_dump(array_column(array(), true));
16+
} catch (\TypeError $e) {
17+
echo $e->getMessage() . "\n";
18+
}
19+
1620

1721
echo "\n-- Testing array_column() column key parameter should be a string or integer (testing array) --\n";
18-
var_dump(array_column(array(), array()));
22+
try {
23+
var_dump(array_column(array(), array()));
24+
} catch (\TypeError $e) {
25+
echo $e->getMessage() . "\n";
26+
}
1927

2028
echo "\n-- Testing array_column() index key parameter should be a string or an integer (testing bool) --\n";
21-
var_dump(array_column(array(), 'foo', true));
29+
try {
30+
var_dump(array_column(array(), 'foo', true));
31+
} catch (\TypeError $e) {
32+
echo $e->getMessage() . "\n";
33+
}
2234

2335
echo "\n-- Testing array_column() index key parameter should be a string or integer (testing array) --\n";
24-
var_dump(array_column(array(), 'foo', array()));
36+
try {
37+
var_dump(array_column(array(), 'foo', array()));
38+
} catch (\TypeError $e) {
39+
echo $e->getMessage() . "\n";
40+
}
2541

26-
echo "Done\n";
2742
?>
28-
--EXPECTF--
43+
44+
DONE
45+
--EXPECT--
2946
*** Testing array_column() : error conditions ***
3047

3148
-- Testing array_column() column key parameter should be a string or an integer (testing bool) --
32-
33-
Warning: array_column(): The column key should be either a string or an integer in %s on line %d
34-
bool(false)
49+
The column key should be either a string or an integer
3550

3651
-- Testing array_column() column key parameter should be a string or integer (testing array) --
37-
38-
Warning: array_column(): The column key should be either a string or an integer in %s on line %d
39-
bool(false)
52+
The column key should be either a string or an integer
4053

4154
-- Testing array_column() index key parameter should be a string or an integer (testing bool) --
42-
43-
Warning: array_column(): The index key should be either a string or an integer in %s on line %d
44-
bool(false)
55+
The index key should be either a string or an integer
4556

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

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

0 commit comments

Comments
 (0)