Skip to content

Commit fb4554e

Browse files
committed
Throw warning for failed object to int/float conversion
We previously couldn't increase the error level here because it was coupled to comparison handling. This is no longer the case in PHP 8.
1 parent d60c43e commit fb4554e

17 files changed

+41
-58
lines changed

Zend/tests/bug33999.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ object(Foo)#1 (1) {
2323
string(3) "bat"
2424
}
2525

26-
Notice: Object of class Foo could not be converted to int in %sbug33999.php on line 9
26+
Warning: Object of class Foo could not be converted to int in %s on line %d
2727
int(1)
2828

29-
Notice: Object of class Foo could not be converted to float in %sbug33999.php on line 12
29+
Warning: Object of class Foo could not be converted to float in %s on line %d
3030
float(1)

Zend/tests/cast_to_double.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ float(1)
5252
float(0)
5353
float(%f)
5454

55-
Notice: Object of class test could not be converted to float in %s on line %d
55+
Warning: Object of class test could not be converted to float in %s on line %d
5656
float(1)
5757
Done

Zend/tests/cast_to_int.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ int(1)
5050
int(0)
5151
int(%d)
5252

53-
Notice: Object of class test could not be converted to int in %s on line %d
53+
Warning: Object of class test could not be converted to int in %s on line %d
5454
int(1)
5555
Done

Zend/tests/offset_string.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Warning: String offset cast occurred in %s on line %d
6969
string(1) "S"
7070
Cannot access offset of type resource on string
7171

72-
Notice: Object of class stdClass could not be converted to int in %s on line %d
72+
Warning: Object of class stdClass could not be converted to int in %s on line %d
7373
Cannot access offset of type stdClass on string
7474
Cannot access offset of type array on string
7575
Done

Zend/tests/settype_double.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ float(1)
5252
float(0)
5353
float(%f)
5454

55-
Notice: Object of class test could not be converted to float in %s on line %d
55+
Warning: Object of class test could not be converted to float in %s on line %d
5656
float(1)
5757
Done

Zend/tests/settype_int.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ int(1)
5050
int(0)
5151
int(%d)
5252

53-
Notice: Object of class test could not be converted to int in %s on line %d
53+
Warning: Object of class test could not be converted to int in %s on line %d
5454
int(1)
5555
Done

Zend/zend_operators.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, size_t str_len) /* {
142142
#define convert_object_to_type(op, dst, ctype) \
143143
ZVAL_UNDEF(dst); \
144144
if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), dst, ctype) == FAILURE) { \
145-
zend_error(E_NOTICE, \
145+
zend_error(E_WARNING, \
146146
"Object of class %s could not be converted to %s", ZSTR_VAL(Z_OBJCE_P(op)->name),\
147147
zend_get_type_by_const(ctype)); \
148148
} \

ext/gd/tests/bug67248.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ for($i=0;$i<7;$i++) {
1919
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
2020
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
2121

22-
Notice: Object of class stdClass could not be converted to float in %s on line %d
22+
Warning: Object of class stdClass could not be converted to float in %s on line %d
2323
array(6) {
2424
[0]=>
2525
float(%f)
@@ -35,7 +35,7 @@ array(6) {
3535
float(0)
3636
}
3737

38-
Notice: Object of class stdClass could not be converted to float in %s on line %d
38+
Warning: Object of class stdClass could not be converted to float in %s on line %d
3939
array(6) {
4040
[0]=>
4141
float(1)
@@ -51,7 +51,7 @@ array(6) {
5151
float(0)
5252
}
5353

54-
Notice: Object of class stdClass could not be converted to float in %s on line %d
54+
Warning: Object of class stdClass could not be converted to float in %s on line %d
5555
array(6) {
5656
[0]=>
5757
float(1)

ext/posix/tests/posix_ttyname_variation6.phpt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ if (!extension_loaded('posix')) {
1616

1717
echo "*** Test substituting argument 1 with object values ***\n";
1818

19-
20-
21-
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
22-
if (error_reporting() != 0) {
23-
// report non-silenced errors
24-
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
25-
}
26-
}
27-
set_error_handler('test_error_handler');
28-
29-
30-
3119
class classWithToString
3220
{
3321
public function __toString() {
@@ -51,7 +39,9 @@ foreach ( $variation_array as $var ) {
5139
?>
5240
--EXPECTF--
5341
*** Test substituting argument 1 with object values ***
54-
Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
42+
43+
Warning: Object of class classWithToString could not be converted to int in %s on line %d
5544
bool(false)
56-
Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
45+
46+
Warning: Object of class classWithoutToString could not be converted to int in %s on line %d
5747
bool(false)

ext/spl/tests/countable_count_variation1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Count returns a string:
6060
int(0)
6161
Count returns an object:
6262

63-
Notice: Object of class returnObject could not be converted to int in %s on line 40
63+
Warning: Object of class returnObject could not be converted to int in %s on line %d
6464
int(1)
6565
Count returns an array:
6666
int(1)

0 commit comments

Comments
 (0)