Doc #77838 [Opn->Csd]: version_compare() returns null when invalid operator given

From: Date: Wed, 03 Apr 2019 17:22:11 +0000
Subject: Doc #77838 [Opn->Csd]: version_compare() returns null when invalid operator given
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16542@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77838&edit=1 ID: 77838 Updated by: cmb@php.net Reported by: ravage at bluewin dot ch Summary: version_compare() returns null when invalid operator given -Status: Open +Status: Closed Type: Documentation Problem Package: PHP options/info functions Operating System: any PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2019-04-03 17:21:42] cmb@php.net Automatic comment from SVN on behalf of cmb Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=347125 Log: Fix #77838: version_compare() returns null when invalid operator given ------------------------------------------------------------------------ [2019-04-03 14:46:59] ravage at bluewin dot ch 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 this bug report at https://bugs.php.net/bug.php?id=77838&edit=1

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