Skip to content

Commit 7dcbcd4

Browse files
committed
Promote warnings to errors in array_column()
1 parent cee24be commit 7dcbcd4

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

ext/standard/array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,7 +4131,7 @@ zend_bool array_column_param_helper(zval *param,
41314131
return 1;
41324132

41334133
default:
4134-
php_error_docref(NULL, E_WARNING, "The %s key should be either a string or an integer", name);
4134+
zend_type_error("The %s key should be either a string or an integer", name);
41354135
return 0;
41364136
}
41374137
}
@@ -4194,7 +4194,7 @@ PHP_FUNCTION(array_column)
41944194

41954195
if ((column && !array_column_param_helper(column, "column")) ||
41964196
(index && !array_column_param_helper(index, "index"))) {
4197-
RETURN_FALSE;
4197+
return;
41984198
}
41994199

42004200
array_init_size(return_value, zend_hash_num_elements(input));

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)