[php-src] Issue #9437: Non-strict comparation of object and scalar value
| From: | WinterSilence | Date: | Fri, 26 Aug 2022 16:39:58 +0000 |
| Subject: | [php-src] Issue #9437: Non-strict comparation of object and scalar value | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242317@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9437
Author: WinterSilence
### Description
The following code:
```php
<?php
class Foo
{
public $bar = 1;
}
$o = new Foo();
$s = '1';
$b = true;
$i = 1;
$f = 1.0;
var_dump($o == $s);
var_dump($o == $b);
var_dump($o == $i);
var_dump($o == $f);
```
Resulted in this output:
```
bool(false)
bool(true)
Notice: Object of class Foo could not be converted to int in /in/mreGe on line 16
bool(true)
Notice: Object of class Foo could not be converted to float in /in/mreGe on line 17
bool(true)
```
But I expected this output instead:
```
bool(true)
bool(true)
bool(true)
bool(true)
```
or
```
Notice: Object of class Foo could not be converted to string in /in/mreGe on line 14
bool(false)
Notice: Object of class Foo could not be converted to bool in /in/mreGe on line 15
bool(false)
Notice: Object of class Foo could not be converted to int in /in/mreGe on line 16
bool(false)
Notice: Object of class Foo could not be converted to float in /in/mreGe on line 17
bool(false)
```
**I can't find any logic in current behavior**:
- Why i can compare non-stringable object with string or bool, but can't compare with
int/float?
- Why i can compare non-stringable object with string without notice?
- If object can't be converted to int/float why comparation return
true?
### PHP Version
PHP 8.0.22
### Operating System
_No response_