mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
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.
This commit is contained in:
parent
d60c43e397
commit
fb4554e431
17 changed files with 41 additions and 58 deletions
|
@ -23,8 +23,8 @@ object(Foo)#1 (1) {
|
|||
string(3) "bat"
|
||||
}
|
||||
|
||||
Notice: Object of class Foo could not be converted to int in %sbug33999.php on line 9
|
||||
Warning: Object of class Foo could not be converted to int in %s on line %d
|
||||
int(1)
|
||||
|
||||
Notice: Object of class Foo could not be converted to float in %sbug33999.php on line 12
|
||||
Warning: Object of class Foo could not be converted to float in %s on line %d
|
||||
float(1)
|
||||
|
|
|
@ -52,6 +52,6 @@ float(1)
|
|||
float(0)
|
||||
float(%f)
|
||||
|
||||
Notice: Object of class test could not be converted to float in %s on line %d
|
||||
Warning: Object of class test could not be converted to float in %s on line %d
|
||||
float(1)
|
||||
Done
|
||||
|
|
|
@ -50,6 +50,6 @@ int(1)
|
|||
int(0)
|
||||
int(%d)
|
||||
|
||||
Notice: Object of class test could not be converted to int in %s on line %d
|
||||
Warning: Object of class test could not be converted to int in %s on line %d
|
||||
int(1)
|
||||
Done
|
||||
|
|
|
@ -69,7 +69,7 @@ Warning: String offset cast occurred in %s on line %d
|
|||
string(1) "S"
|
||||
Cannot access offset of type resource on string
|
||||
|
||||
Notice: Object of class stdClass could not be converted to int in %s on line %d
|
||||
Warning: Object of class stdClass could not be converted to int in %s on line %d
|
||||
Cannot access offset of type stdClass on string
|
||||
Cannot access offset of type array on string
|
||||
Done
|
||||
|
|
|
@ -52,6 +52,6 @@ float(1)
|
|||
float(0)
|
||||
float(%f)
|
||||
|
||||
Notice: Object of class test could not be converted to float in %s on line %d
|
||||
Warning: Object of class test could not be converted to float in %s on line %d
|
||||
float(1)
|
||||
Done
|
||||
|
|
|
@ -50,6 +50,6 @@ int(1)
|
|||
int(0)
|
||||
int(%d)
|
||||
|
||||
Notice: Object of class test could not be converted to int in %s on line %d
|
||||
Warning: Object of class test could not be converted to int in %s on line %d
|
||||
int(1)
|
||||
Done
|
||||
|
|
|
@ -142,7 +142,7 @@ ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, size_t str_len) /* {
|
|||
#define convert_object_to_type(op, dst, ctype) \
|
||||
ZVAL_UNDEF(dst); \
|
||||
if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), dst, ctype) == FAILURE) { \
|
||||
zend_error(E_NOTICE, \
|
||||
zend_error(E_WARNING, \
|
||||
"Object of class %s could not be converted to %s", ZSTR_VAL(Z_OBJCE_P(op)->name),\
|
||||
zend_get_type_by_const(ctype)); \
|
||||
} \
|
||||
|
|
|
@ -19,7 +19,7 @@ for($i=0;$i<7;$i++) {
|
|||
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
|
||||
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
|
||||
|
||||
Notice: Object of class stdClass could not be converted to float in %s on line %d
|
||||
Warning: Object of class stdClass could not be converted to float in %s on line %d
|
||||
array(6) {
|
||||
[0]=>
|
||||
float(%f)
|
||||
|
@ -35,7 +35,7 @@ array(6) {
|
|||
float(0)
|
||||
}
|
||||
|
||||
Notice: Object of class stdClass could not be converted to float in %s on line %d
|
||||
Warning: Object of class stdClass could not be converted to float in %s on line %d
|
||||
array(6) {
|
||||
[0]=>
|
||||
float(1)
|
||||
|
@ -51,7 +51,7 @@ array(6) {
|
|||
float(0)
|
||||
}
|
||||
|
||||
Notice: Object of class stdClass could not be converted to float in %s on line %d
|
||||
Warning: Object of class stdClass could not be converted to float in %s on line %d
|
||||
array(6) {
|
||||
[0]=>
|
||||
float(1)
|
||||
|
|
|
@ -16,18 +16,6 @@ if (!extension_loaded('posix')) {
|
|||
|
||||
echo "*** Test substituting argument 1 with object values ***\n";
|
||||
|
||||
|
||||
|
||||
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
|
||||
if (error_reporting() != 0) {
|
||||
// report non-silenced errors
|
||||
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
|
||||
}
|
||||
}
|
||||
set_error_handler('test_error_handler');
|
||||
|
||||
|
||||
|
||||
class classWithToString
|
||||
{
|
||||
public function __toString() {
|
||||
|
@ -51,7 +39,9 @@ foreach ( $variation_array as $var ) {
|
|||
?>
|
||||
--EXPECTF--
|
||||
*** Test substituting argument 1 with object values ***
|
||||
Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
|
||||
|
||||
Warning: Object of class classWithToString could not be converted to int in %s on line %d
|
||||
bool(false)
|
||||
Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
|
||||
|
||||
Warning: Object of class classWithoutToString could not be converted to int in %s on line %d
|
||||
bool(false)
|
||||
|
|
|
@ -60,7 +60,7 @@ Count returns a string:
|
|||
int(0)
|
||||
Count returns an object:
|
||||
|
||||
Notice: Object of class returnObject could not be converted to int in %s on line 40
|
||||
Warning: Object of class returnObject could not be converted to int in %s on line %d
|
||||
int(1)
|
||||
Count returns an array:
|
||||
int(1)
|
||||
|
|
|
@ -33,13 +33,13 @@ var_dump($inputs);
|
|||
--EXPECTF--
|
||||
*** Testing array_multisort() : usage variation - test sort order of all types***
|
||||
|
||||
Notice: Object of class classWithToString could not be converted to float in %sarray_multisort_variation9.php on line %d
|
||||
Warning: Object of class classWithToString could not be converted to float in %s on line %d
|
||||
|
||||
Notice: Object of class classWithToString could not be converted to float in %sarray_multisort_variation9.php on line %d
|
||||
Warning: Object of class classWithToString could not be converted to float in %s on line %d
|
||||
|
||||
Notice: Object of class classWithoutToString could not be converted to float in %sarray_multisort_variation9.php on line %d
|
||||
Warning: Object of class classWithoutToString could not be converted to float in %s on line %d
|
||||
|
||||
Notice: Object of class classWithoutToString could not be converted to float in %sarray_multisort_variation9.php on line %d
|
||||
Warning: Object of class classWithoutToString could not be converted to float in %s on line %d
|
||||
bool(true)
|
||||
array(10) {
|
||||
["float -10.5"]=>
|
||||
|
|
|
@ -237,7 +237,7 @@ bool(true)
|
|||
int(%d)
|
||||
string(7) "integer"
|
||||
-- Iteration 14 --
|
||||
8: Object of class point could not be converted to int
|
||||
2: Object of class point could not be converted to int
|
||||
bool(true)
|
||||
int(1)
|
||||
string(7) "integer"
|
||||
|
@ -296,7 +296,7 @@ bool(true)
|
|||
int(%d)
|
||||
string(7) "integer"
|
||||
-- Iteration 14 --
|
||||
8: Object of class point could not be converted to int
|
||||
2: Object of class point could not be converted to int
|
||||
bool(true)
|
||||
int(1)
|
||||
string(7) "integer"
|
||||
|
@ -355,7 +355,7 @@ bool(true)
|
|||
float(%f)
|
||||
string(6) "double"
|
||||
-- Iteration 14 --
|
||||
8: Object of class point could not be converted to float
|
||||
2: Object of class point could not be converted to float
|
||||
bool(true)
|
||||
float(1)
|
||||
string(6) "double"
|
||||
|
@ -414,7 +414,7 @@ bool(true)
|
|||
float(%f)
|
||||
string(6) "double"
|
||||
-- Iteration 14 --
|
||||
8: Object of class point could not be converted to float
|
||||
2: Object of class point could not be converted to float
|
||||
bool(true)
|
||||
float(1)
|
||||
string(6) "double"
|
||||
|
|
|
@ -554,19 +554,19 @@ int(-512000)
|
|||
string(7) "integer"
|
||||
-- Iteration 76 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to int
|
||||
2: Object of class point could not be converted to int
|
||||
bool(true)
|
||||
int(1)
|
||||
string(7) "integer"
|
||||
-- Iteration 77 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to int
|
||||
2: Object of class point could not be converted to int
|
||||
bool(true)
|
||||
int(1)
|
||||
string(7) "integer"
|
||||
-- Iteration 78 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to int
|
||||
2: Object of class point could not be converted to int
|
||||
bool(true)
|
||||
int(1)
|
||||
string(7) "integer"
|
||||
|
@ -949,19 +949,19 @@ int(-512000)
|
|||
string(7) "integer"
|
||||
-- Iteration 76 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to int
|
||||
2: Object of class point could not be converted to int
|
||||
bool(true)
|
||||
int(1)
|
||||
string(7) "integer"
|
||||
-- Iteration 77 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to int
|
||||
2: Object of class point could not be converted to int
|
||||
bool(true)
|
||||
int(1)
|
||||
string(7) "integer"
|
||||
-- Iteration 78 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to int
|
||||
2: Object of class point could not be converted to int
|
||||
bool(true)
|
||||
int(1)
|
||||
string(7) "integer"
|
||||
|
|
|
@ -548,19 +548,19 @@ float(-512000)
|
|||
string(6) "double"
|
||||
-- Iteration 76 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to float
|
||||
2: Object of class point could not be converted to float
|
||||
bool(true)
|
||||
float(1)
|
||||
string(6) "double"
|
||||
-- Iteration 77 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to float
|
||||
2: Object of class point could not be converted to float
|
||||
bool(true)
|
||||
float(1)
|
||||
string(6) "double"
|
||||
-- Iteration 78 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to float
|
||||
2: Object of class point could not be converted to float
|
||||
bool(true)
|
||||
float(1)
|
||||
string(6) "double"
|
||||
|
@ -943,19 +943,19 @@ float(-512000)
|
|||
string(6) "double"
|
||||
-- Iteration 76 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to float
|
||||
2: Object of class point could not be converted to float
|
||||
bool(true)
|
||||
float(1)
|
||||
string(6) "double"
|
||||
-- Iteration 77 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to float
|
||||
2: Object of class point could not be converted to float
|
||||
bool(true)
|
||||
float(1)
|
||||
string(6) "double"
|
||||
-- Iteration 78 --
|
||||
string(6) "object"
|
||||
8: Object of class point could not be converted to float
|
||||
2: Object of class point could not be converted to float
|
||||
bool(true)
|
||||
float(1)
|
||||
string(6) "double"
|
||||
|
|
|
@ -4,15 +4,6 @@ Test intval() function : usage variation
|
|||
<?php
|
||||
echo "*** Testing intval() : usage variation ***\n";
|
||||
|
||||
// Define error handler
|
||||
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
|
||||
if (error_reporting() & $err_no) {
|
||||
// report non-silenced errors
|
||||
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
|
||||
}
|
||||
}
|
||||
set_error_handler('test_error_handler');
|
||||
|
||||
// Initialise function arguments not being substituted (if any)
|
||||
$base = 10;
|
||||
|
||||
|
@ -181,11 +172,13 @@ int(0)
|
|||
int(0)
|
||||
|
||||
--instance of classWithToString--
|
||||
Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
|
||||
|
||||
Warning: Object of class classWithToString could not be converted to int in %s on line %d
|
||||
int(1)
|
||||
|
||||
--instance of classWithoutToString--
|
||||
Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
|
||||
|
||||
Warning: Object of class classWithoutToString could not be converted to int in %s on line %d
|
||||
int(1)
|
||||
|
||||
--undefined var--
|
||||
|
|
Binary file not shown.
|
@ -162,7 +162,7 @@ bool(true)
|
|||
|
||||
Arg value Some Ascii Data
|
||||
|
||||
Notice: Object of class aClass could not be converted to int in %s on line %d
|
||||
Warning: Object of class aClass could not be converted to int in %s on line %d
|
||||
bool(true)
|
||||
|
||||
Arg value Resource id %s
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue