note 108563 added to function.strcmp
| From: | jendoj at gmail dot com | Date: | Mon, 07 May 2012 11:00:41 +0000 |
| Subject: | note 108563 added to function.strcmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187505@lists.php.net to get a copy of this message | ||
If you rely on strcmp for safe string comparisons, both parameters must be strings, the result is
otherwise extremely unpredictable.
For instance you may get an unexpected 0, or return values of NULL, -2, 2, 3 and -3.
strcmp("5", 5) => 0
strcmp("15", 0xf) => 0
strcmp(61529519452809720693702583126814, 61529519452809720000000000000000) => 0
strcmp(NULL, false) => 0
strcmp(NULL, "") => 0
strcmp(NULL, 0) => -1
strcmp(false, -1) => -2
strcmp("15", NULL) => 2
strcmp(NULL, "foo") => -3
strcmp("foo", NULL) => 3
strcmp("foo", false) => 3
strcmp("foo", 0) => 1
strcmp("foo", 5) => 1
strcmp("foo", array()) => NULL + PHP Warning
strcmp("foo", new stdClass) => NULL + PHP Warning
strcmp(function(){}, "") => NULL + PHP Warning
----
Server IP: 69.147.83.197
Probable Submitter: 86.135.162.90
----
Manual Page -- http://www.php.net/manual/en/function.strcmp.php
Edit -- https://master.php.net/note/edit/108563
Del: integrated -- https://master.php.net/note/delete/108563/integrated
Del: useless -- https://master.php.net/note/delete/108563/useless
Del: bad code -- https://master.php.net/note/delete/108563/bad+code
Del: spam -- https://master.php.net/note/delete/108563/spam
Del: non-english -- https://master.php.net/note/delete/108563/non-english
Del: in docs -- https://master.php.net/note/delete/108563/in+docs
Del: other reasons-- https://master.php.net/note/delete/108563
Reject -- https://master.php.net/note/reject/108563
Search -- https://master.php.net/manage/user-notes.php