Bug #53999 [Wfx]: strcmp() doesn't always return -1, 0, or 1
| From: | charlie at charliesomerville dot com | Date: | Sat, 12 Feb 2011 07:35:09 +0000 |
| Subject: | Bug #53999 [Wfx]: strcmp() doesn't always return -1, 0, or 1 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-158725@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53999&edit=1
ID: 53999
User updated by: charlie at charliesomerville dot com
Reported by: charlie at charliesomerville dot com
Summary: strcmp() doesn't always return -1, 0, or 1
Status: Wont fix
Type: Bug
Package: SPL related
Operating System: Mac OS X
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
While I know that all the documentation promises is < 0, == 0 and > 0,
as PHP is
supposed to provide an OS-agnostic environment, shouldn't strcmp()
return
consistent values across the board?
Previous Comments:
------------------------------------------------------------------------
[2011-02-12 08:32:02] kalle@php.net
The documentation for strcmp() does not state it returns -1, 0 or 1:
"Returns < 0 if str1 is less than str2; > 0 if str1 is greater than
str2, and 0 if they are equal."
The memcmp() man page also states that (which is what strcmp internally
uses), so if you want the same cross platform behaviour you should alter
your script to do as specified above.
------------------------------------------------------------------------
[2011-02-12 08:09:56] charlie at charliesomerville dot com
Description:
------------
PHP's strcmp() return value is inconsistent across operating systems.
On Windows and Linux, strcmp("foo","bar") returns 1. However, on Mac OS
X,
strcmp("foo","bar") returns 4.
Technically, both of these return values are correct, however the 4 is
inconsistent with the return values on other operating systems.
Test script:
---------------
<?php
echo strcmp("foo","bar");
Expected result:
----------------
1
Actual result:
--------------
4
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53999&edit=1