note 129333 added to function.version-compare
| From: | hello@chrisreynolds.io | Date: | Thu, 14 Mar 2024 17:14:06 +0000 |
| Subject: | note 129333 added to function.version-compare | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221247@lists.php.net to get a copy of this message | ||
Worth noting that
-1 is not equivalent to false. Which is to say that:
$current_version = "1.0.0";
$compared_version = "1.2.0";
// if ( 1 )
if (version_compare($current_version, $compared_version) {
echo "A newer version is available"; // this is true
}
but also
$current_version = "1.3.0";
$compared_version = "1.2.0";
// if ( -1 )
if (version_compare($current_version, $compared_version) {
echo "You are on the most recent version."; // this is also true
}
In other words, don't rely on the default behavior (the first value is greater than the second
value) if what you want is a boolean.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.131 (proxied: 2605:a601:a9ee:e600:7919:ede0:7811:48ca)
----
Manual Page -- https://php.net/manual/en/function.version-compare.php
Edit -- https://main.php.net/note/edit/129333
Del: integrated -- https://main.php.net/note/delete/129333/integrated
Del: useless -- https://main.php.net/note/delete/129333/useless
Del: bad code -- https://main.php.net/note/delete/129333/bad+code
Del: spam -- https://main.php.net/note/delete/129333/spam
Del: non-english -- https://main.php.net/note/delete/129333/non-english
Del: in docs -- https://main.php.net/note/delete/129333/in+docs
Del: other reasons-- https://main.php.net/note/delete/129333
Reject -- https://main.php.net/note/reject/129333
Search -- https://main.php.net/manage/user-notes.php