Doc #77838 [NEW]: version_compare() returns null when invalid operator given

From: Date: Wed, 03 Apr 2019 14:46:59 +0000
Subject: Doc #77838 [NEW]: version_compare() returns null when invalid operator given
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16539@lists.php.net to get a copy of this message
From: ravage at bluewin dot ch Operating system: any PHP version: Irrelevant Package: PHP options/info functions Bug Type: Documentation Problem Bug description:version_compare() returns null when invalid operator given Description: ------------ According to the documentation of the version_compare() function, it returns either true or false, if there is an operator parameter given. https://www.php.net/manual/en/function.version-compare.php But it seems it can also return null, if there is an invalid operator string given. Invalid can be at least either a totally wrong operator, e.g. "invalid", a space " " or a valid operator string pre- or suffixed with a space, e.g " ge". This is certainly a documentation issue but for the future this could be improved by throwing an exception, e.g. InvalidArgumentException. By the way this was reported as a comment on the function's documentation page at https://www.php.net/manual/en/function.version-compare.php#106715 Test script: --------------- <?php var_dump(version_compare('3.7.5', '3.7.0', 'ge')); // true, OK var_dump(version_compare('3.7.5', '3.7.0', ' ')); // null, should throw invalid argument exception at best var_dump(version_compare('3.7.5', '3.7.0', ' ge')); // null, should throw invalid argument exception at best var_dump(version_compare('3.7.5', '3.7.0', 'ge ')); // null, should throw invalid argument exception at best var_dump(version_compare('3.7.5', '3.7.0', 'invalid')); // null, should throw invalid argument exception at best ?> https://3v4l.org/CrO0J Expected result: ---------------- That the possible return value of null is officially documented at https://www.php.net/manual/en/function.version-compare.php. Even better would be an exception thrown, e.g. InvalidArgumentException. Actual result: -------------- null (officially undocumented) -- Edit bug report at https://bugs.php.net/bug.php?id=77838&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77838&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77838&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77838&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77838&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77838&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77838&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77838&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77838&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77838&r=support Expected behavior: https://bugs.php.net/fix.php?id=77838&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77838&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77838&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77838&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77838&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77838&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77838&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77838&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77838&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77838&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77838&r=mysqlcfg

« previous php.doc.bugs (#16539) next »