php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50381 Error in version_compare() example
Submitted: 2009-12-04 10:19 UTC Modified: 2009-12-07 14:48 UTC
From: a dot schilder at gmx dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
 [2009-12-04 10:19 UTC] a dot schilder at gmx dot de
Description:
------------
The first two examples for version_compare() are wrong - the code does not match the printed text ("at least" although the check matches greater versions).



Reproduce code:
---------------
---
From manual page: function.version-compare
---
<?php
if (version_compare(PHP_VERSION, '6.0.0') === 1) {
    echo 'I am at least PHP version 6.0.0, my version: ' . PHP_VERSION . "\n";
}

if (version_compare(PHP_VERSION, '5.3.0') === 1) {
    echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "\n";
}
?>

Expected result:
----------------
<?php
if (version_compare(PHP_VERSION, '6.0.0') >= 0) {
    echo 'I am at least PHP version 6.0.0, my version: ' . PHP_VERSION . "\n";
}

if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "\n";
}
?>

OR

<?php
if (version_compare(PHP_VERSION, '6.0.0') === 1) {
    echo 'I am greater PHP version 6.0.0, my version: ' . PHP_VERSION . "\n";
}

if (version_compare(PHP_VERSION, '5.3.0') === 1) {
    echo 'I am greater PHP version 5.3.0, my version: ' . PHP_VERSION . "\n";
}
?>

OR BOTH...

Actual result:
--------------
PHP 5.3.0:
(no output)

PHP 5.3.1:
I am at least PHP version 5.3.0, my version: 5.3.1

PHP 6.0.0:
I am at least PHP version 5.3.0, my version: 6.0.0

PHP 6.0.1:
I am at least PHP version 6.0.0, my version: 6.0.1
I am at least PHP version 5.3.0, my version: 6.0.1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-07 14:48 UTC] svn@php.net
Automatic comment from SVN on behalf of rquadling
Revision: http://svn.php.net/viewvc/?view=revision&revision=291819
Log: Example fixed. Fix #50381
 [2009-12-07 14:48 UTC] rquadling@php.net
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.


 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of rquadling
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=d9860137677e44398d5bf360ffce837e5849b569
Log: Example fixed. Fix #50381
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 07:00:01 2026 UTC