[php-src] Issue #13535: Unexpected return values: strcmp(), strncmp(), strcasecmp(), strncasecmp
| From: | s-heinrich-igniti-de | Date: | Tue, 27 Feb 2024 16:48:59 +0000 |
| Subject: | [php-src] Issue #13535: Unexpected return values: strcmp(), strncmp(), strcasecmp(), strncasecmp | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246483@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13535
Author: s-heinrich-igniti-de
### Description
_Disclaimer: This is my first bug report, I researched but didn't find anything related. Please
request if any further information is required or close this report if it isn't valid._
**Description:**
During PHP 8.1 to 8.3 update check for a project I found change information regarding return values
of strcmp(), strncmp(), stcasecmp() and strncasecmp() in PHP 8.2:
* https://www.php.net/manual/en/migration82.other-changes.php#migration82.other-changes.functions.core
The new return values are also mentioned on each of the documentation pages.
**Expected behavior:**
* return values: 0, -1 and 1
**Actual behavior:**
* different return values (see below)
**Environment:**
* Linux Mint 21.3 Virginia
* different PHP versions by: ppa:ondrej/php
**test.php:**
```php
<?php
var_dump(
strcmp('bar', 'foo'),
strcmp('foo', 'bar'),
strcasecmp('bar', 'foo'),
strcasecmp('foo', 'bar'),
strncmp('bar', 'foo', 2),
strncmp('foo', 'bar', 2),
strncasecmp('bar', 'foo', 2),
strncasecmp('foo', 'bar', 2),
);
```
**Output:**
* 8.1:
```
$ /usr/bin/php8.1 -v && /usr/bin/php8.1 -f test.php
PHP 8.1.27 (cli) (built: Dec 21 2023 20:19:54) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.27, Copyright (c) Zend Technologies
with Zend OPcache v8.1.27, Copyright (c), by Zend Technologies
int(-4)
int(4)
int(-4)
int(4)
int(-4)
int(4)
int(-4)
int(4)
```
* 8.2:
```
$ /usr/bin/php8.2 -v && /usr/bin/php8.2 -f test.php
PHP 8.2.15 (cli) (built: Jan 20 2024 14:17:05) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.15, Copyright (c) Zend Technologies
with Zend OPcache v8.2.15, Copyright (c), by Zend Technologies
int(-4)
int(4)
int(-4)
int(4)
int(-4)
int(4)
int(-4)
int(4)
```
* 8.3:
```
$ /usr/bin/php8.3 -v && /usr/bin/php8.3 -f test.php
PHP 8.3.3-1+ubuntu22.04.1+deb.sury.org+1 (cli) (built: Feb 15 2024 18:38:52) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.3, Copyright (c) Zend Technologies
with Zend OPcache v8.3.3-1+ubuntu22.04.1+deb.sury.org+1, Copyright (c), by Zend Technologies
int(-4)
int(4)
int(-4)
int(4)
int(-4)
int(4)
int(-4)
int(4)
```
---
Additionally (better: confusingly), I get a different output here: https://3v4l.org/C1i18 (please check current 8.2 and 8.3 versions
separately - all supported versions include version 8.1).
```
int(-265725)
int(265725)
int(-4)
int(4)
int(-265742)
int(265742)
int(-4)
int(4)
```
### PHP Version
PHP 8.2 / PHP 8.3
### Operating System
Linux Mint 21.3