Doc #65362 [NEW]: strcmp null return missing from docs.
From: atli dot jonsson at ymail dot com
Operating system:
PHP version: 5.5.1
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:strcmp null return missing from docs.
Description:
------------
strcmp, strncmp, strcasecmp and strncasecmp will all return NULL when
either
string parameter is of a type that is invalid for string conversions, like
Arrays,
Objects and Resources.
However, the docs make no mention of this fact. (Aside from a comment.) As
the 0
value returned for equal strings, and NULL returned for invalid
comparisons, are
equal when compared in a non-strict manner, this can lead to unexpected
behaviour.
There is a warning issued, but without clarification the above is still in
no way
obvious.
Test script:
---------------
<?php
$arr = [];
$str = "PHP is awesome!";
if (strcmp($arr, $str) == 0) {
echo "Equal!"; // Ends up here.
}
else {
echo "Not equal!";
}
--
Edit bug report at https://bugs.php.net/bug.php?id=65362&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65362&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65362&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65362&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65362&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65362&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65362&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65362&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65362&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65362&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65362&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65362&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65362&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65362&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65362&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65362&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65362&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65362&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65362&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65362&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65362&r=mysqlcfg
Thread (1 message)
- atli dot jonsson at ymail dot com