[php-src] Issue #10513: Spaceship operator fails on long strings
| From: | TomHAnderson | Date: | Sun, 05 Feb 2023 21:55:37 +0000 |
| Subject: | [php-src] Issue #10513: Spaceship operator fails on long strings | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243650@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10513
Author: TomHAnderson
### Description
The following code:
```php
<?php
```
$hashA = '00000000000007e60000000000000000';
$hashB = '00000000000053110000000000000000';
for ($i = 15; $i <= 16; $i ++) {
$subA = substr($hashA, 0, $i);
$subB = substr($hashB, 0, $i);
echo $subA . "\n";
echo $subB . "\n";
$spaceship = $subA <=> $subB;
if ($spaceship > 0) {
echo ('Non-equal strings do not return -1 for spaceship operator: ' . $subA . '
' . $subB . "\n");
}
$strcasecmp = strcmp($subA, $subB);
if ($strcasecmp > 0) {
echo ('Non-equal strings do not return -1 for strcasecmp: ' . $subA . ' ' .
$subB . "\n");
}
echo "\n";
}
Resulted in this output:
```
00000000000007e
000000000000531
00000000000007e6
0000000000005311
Non-equal strings do not return -1 for spaceship operator: 00000000000007e6 0000000000005311
```
But I expected this output instead:
```
00000000000007e
000000000000531
00000000000007e6
0000000000005311
```
### PHP Version
PHP 8.1.14
### Operating System
Mac OS