[php-src] Issue #15003: Comparing string to integer without casting or intval gives unexpected behavior since version 7.4
| From: | AwkAmr | Date: | Wed, 17 Jul 2024 23:24:33 +0000 |
| Subject: | [php-src] Issue #15003: Comparing string to integer without casting or intval gives unexpected behavior since version 7.4 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247312@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15003
Author: AwkAmr
### Description
The following code:
This was tested in multiple environments, including docker container.
```php
<?php
$testStrings = ["Abdelfatah", "hello", "123abc", "abc123",
"", "0"];
foreach ($testStrings as $testString) {
echo "Testing with string: " . var_export($testString, true) . "\n";
echo "Integer conversion: " . var_export((int)$testString, true) . "\n";
echo "Is string > 90: " . var_export($testString > 90, true) . "\n";
echo "Is string == 0: " . var_export($testString == 0, true) . "\n";
echo "Is (int)string > 90: " . var_export(((int)$testString) > 90, true) .
"\n";
echo "intval(string) > 90: " . var_export(intval($testString) > 90, true) .
"\n";
echo "is_numeric(string): " . var_export(is_numeric($testString), true) .
"\n";
echo "\n";
}
```
Resulted in this output: (From latest version 8.3.9)
```Testing with string: 'Abdelfatah'
Integer conversion: 0
Is string > 90: true
Is string == 0: false
Is (int)string > 90: false
intval(string) > 90: false
is_numeric(string): false
Testing with string: 'hello'
Integer conversion: 0
Is string > 90: true
Is string == 0: false
Is (int)string > 90: false
intval(string) > 90: false
is_numeric(string): false
Testing with string: '123abc'
Integer conversion: 123
Is string > 90: false
Is string == 0: false
Is (int)string > 90: true
intval(string) > 90: true
is_numeric(string): false
Testing with string: 'abc123'
Integer conversion: 0
Is string > 90: true
Is string == 0: false
Is (int)string > 90: false
intval(string) > 90: false
is_numeric(string): false
Testing with string: ''
Integer conversion: 0
Is string > 90: false
Is string == 0: false
Is (int)string > 90: false
intval(string) > 90: false
is_numeric(string): false
Testing with string: '0'
Integer conversion: 0
Is string > 90: false
Is string == 0: true
Is (int)string > 90: false
intval(string) > 90: false
is_numeric(string): true
```
But I expected this output instead: (Output gotten from version 7.4.33)
```Testing with string: 'Abdelfatah'
Integer conversion: 0
Is string > 90: false
Is string == 0: true
Is (int)string > 90: false
intval(string) > 90: false
is_numeric(string): false
Testing with string: 'hello'
Integer conversion: 0
Is string > 90: false
Is string == 0: true
Is (int)string > 90: false
intval(string) > 90: false
is_numeric(string): false
Testing with string: '123abc'
Integer conversion: 123
Is string > 90: true
Is string == 0: false
Is (int)string > 90: true
intval(string) > 90: true
is_numeric(string): false
Testing with string: 'abc123'
Integer conversion: 0
Is string > 90: false
Is string == 0: true
Is (int)string > 90: false
intval(string) > 90: false
is_numeric(string): false
Testing with string: ''
Integer conversion: 0
Is string > 90: false
Is string == 0: true
Is (int)string > 90: false
intval(string) > 90: false
is_numeric(string): false
Testing with string: '0'
Integer conversion: 0
Is string > 90: false
Is string == 0: true
Is (int)string > 90: false
intval(string) > 90: false
is_numeric(string): true
```
### PHP Version
8.3.9
### Operating System
_No response_