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)

ext/standard/tests/array/array_multisort_variation9.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ var_dump($inputs);
3333
--EXPECTF--
3434
*** Testing array_multisort() : usage variation - test sort order of all types***
3535

36-
Notice: Object of class classWithToString could not be converted to float in %sarray_multisort_variation9.php on line %d
36+
Warning: Object of class classWithToString could not be converted to float in %s on line %d
3737

38-
Notice: Object of class classWithToString could not be converted to float in %sarray_multisort_variation9.php on line %d
38+
Warning: Object of class classWithToString could not be converted to float in %s on line %d
3939

40-
Notice: Object of class classWithoutToString could not be converted to float in %sarray_multisort_variation9.php on line %d
40+
Warning: Object of class classWithoutToString could not be converted to float in %s on line %d
4141

42-
Notice: Object of class classWithoutToString could not be converted to float in %sarray_multisort_variation9.php on line %d
42+
Warning: Object of class classWithoutToString could not be converted to float in %s on line %d
4343
bool(true)
4444
array(10) {
4545
["float -10.5"]=>

ext/standard/tests/general_functions/gettype_settype_basic.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ bool(true)
237237
int(%d)
238238
string(7) "integer"
239239
-- Iteration 14 --
240-
8: Object of class point could not be converted to int
240+
2: Object of class point could not be converted to int
241241
bool(true)
242242
int(1)
243243
string(7) "integer"
@@ -296,7 +296,7 @@ bool(true)
296296
int(%d)
297297
string(7) "integer"
298298
-- Iteration 14 --
299-
8: Object of class point could not be converted to int
299+
2: Object of class point could not be converted to int
300300
bool(true)
301301
int(1)
302302
string(7) "integer"
@@ -355,7 +355,7 @@ bool(true)
355355
float(%f)
356356
string(6) "double"
357357
-- Iteration 14 --
358-
8: Object of class point could not be converted to float
358+
2: Object of class point could not be converted to float
359359
bool(true)
360360
float(1)
361361
string(6) "double"
@@ -414,7 +414,7 @@ bool(true)
414414
float(%f)
415415
string(6) "double"
416416
-- Iteration 14 --
417-
8: Object of class point could not be converted to float
417+
2: Object of class point could not be converted to float
418418
bool(true)
419419
float(1)
420420
string(6) "double"

ext/standard/tests/general_functions/gettype_settype_variation2.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,19 +554,19 @@ int(-512000)
554554
string(7) "integer"
555555
-- Iteration 76 --
556556
string(6) "object"
557-
8: Object of class point could not be converted to int
557+
2: Object of class point could not be converted to int
558558
bool(true)
559559
int(1)
560560
string(7) "integer"
561561
-- Iteration 77 --
562562
string(6) "object"
563-
8: Object of class point could not be converted to int
563+
2: Object of class point could not be converted to int
564564
bool(true)
565565
int(1)
566566
string(7) "integer"
567567
-- Iteration 78 --
568568
string(6) "object"
569-
8: Object of class point could not be converted to int
569+
2: Object of class point could not be converted to int
570570
bool(true)
571571
int(1)
572572
string(7) "integer"
@@ -949,19 +949,19 @@ int(-512000)
949949
string(7) "integer"
950950
-- Iteration 76 --
951951
string(6) "object"
952-
8: Object of class point could not be converted to int
952+
2: Object of class point could not be converted to int
953953
bool(true)
954954
int(1)
955955
string(7) "integer"
956956
-- Iteration 77 --
957957
string(6) "object"
958-
8: Object of class point could not be converted to int
958+
2: Object of class point could not be converted to int
959959
bool(true)
960960
int(1)
961961
string(7) "integer"
962962
-- Iteration 78 --
963963
string(6) "object"
964-
8: Object of class point could not be converted to int
964+
2: Object of class point could not be converted to int
965965
bool(true)
966966
int(1)
967967
string(7) "integer"

ext/standard/tests/general_functions/gettype_settype_variation3.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,19 +548,19 @@ float(-512000)
548548
string(6) "double"
549549
-- Iteration 76 --
550550
string(6) "object"
551-
8: Object of class point could not be converted to float
551+
2: Object of class point could not be converted to float
552552
bool(true)
553553
float(1)
554554
string(6) "double"
555555
-- Iteration 77 --
556556
string(6) "object"
557-
8: Object of class point could not be converted to float
557+
2: Object of class point could not be converted to float
558558
bool(true)
559559
float(1)
560560
string(6) "double"
561561
-- Iteration 78 --
562562
string(6) "object"
563-
8: Object of class point could not be converted to float
563+
2: Object of class point could not be converted to float
564564
bool(true)
565565
float(1)
566566
string(6) "double"
@@ -943,19 +943,19 @@ float(-512000)
943943
string(6) "double"
944944
-- Iteration 76 --
945945
string(6) "object"
946-
8: Object of class point could not be converted to float
946+
2: Object of class point could not be converted to float
947947
bool(true)
948948
float(1)
949949
string(6) "double"
950950
-- Iteration 77 --
951951
string(6) "object"
952-
8: Object of class point could not be converted to float
952+
2: Object of class point could not be converted to float
953953
bool(true)
954954
float(1)
955955
string(6) "double"
956956
-- Iteration 78 --
957957
string(6) "object"
958-
8: Object of class point could not be converted to float
958+
2: Object of class point could not be converted to float
959959
bool(true)
960960
float(1)
961961
string(6) "double"

ext/standard/tests/general_functions/intval_variation1.phpt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ Test intval() function : usage variation
44
<?php
55
echo "*** Testing intval() : usage variation ***\n";
66

7-
// Define error handler
8-
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
9-
if (error_reporting() & $err_no) {
10-
// report non-silenced errors
11-
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
12-
}
13-
}
14-
set_error_handler('test_error_handler');
15-
167
// Initialise function arguments not being substituted (if any)
178
$base = 10;
189

@@ -181,11 +172,13 @@ int(0)
181172
int(0)
182173

183174
--instance of classWithToString--
184-
Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
175+
176+
Warning: Object of class classWithToString could not be converted to int in %s on line %d
185177
int(1)
186178

187179
--instance of classWithoutToString--
188-
Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
180+
181+
Warning: Object of class classWithoutToString could not be converted to int in %s on line %d
189182
int(1)
190183

191184
--undefined var--
Binary file not shown.

ext/xml/tests/xml_parser_set_option_variation3.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ bool(true)
162162

163163
Arg value Some Ascii Data
164164

165-
Notice: Object of class aClass could not be converted to int in %s on line %d
165+
Warning: Object of class aClass could not be converted to int in %s on line %d
166166
bool(true)
167167

168168
Arg value Resource id %s

0 commit comments

Comments
 (0)