php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49854 function.phpversion: bad code in manual example
Submitted: 2009-10-13 00:01 UTC Modified: 2009-10-15 16:56 UTC
From: clancyhood at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.3.0 OS: Mac 10.5.2
Private report: No CVE-ID: None
 [2009-10-13 00:01 UTC] clancyhood at gmail dot com
Description:
------------
example #2 erroneously produces a version id of 40301 for version string 4.3.11 since the code $version{4} simply accesses the character at position 4 of the string without regard to the length of the release number.

The releases 4.3.1 and 4.3.11 are over a year apart.  I'd suggest using explode to seperate the version string properly.

<?php

  list($major, $minor, $release) = explode('.', PHP_VERSION);
  define('PHP_VERSION_ID', ($major * 10000 + $minor * 100 + $release));

?>

(BTW, it's terribly frustrating to have wasted one's time adding a note since documentation issues are classed as "bugs". Something to this effect on the "add note" page would have prevented me wasting my time - and so subsequently being able to make a wild guess about how PHP.net runs its site)

Reproduce code:
---------------
---
From manual page: function.phpversion
---
<?php
// PHP_VERSION_ID is available as of PHP 5.2.7, if our 
// version is lower than that, then emulate it
if(!defined('PHP_VERSION_ID'))
{
    $version = PHP_VERSION;

    define('PHP_VERSION_ID', ($version{0} * 10000 + $version{2} * 100 + $version{4}));
}
?> 

Expected result:
----------------
A PHP_VERSION_ID of 40311 for PHP_VERSION 4.3.11

Actual result:
--------------
A PHP_VERSION_ID of 40301 for PHP_VERSION 4.3.11

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-15 16:09 UTC] svn@php.net
Automatic comment from SVN on behalf of danbrown
Revision: http://svn.php.net/viewvc/?view=revision&revision=289673
Log: Addresses Bug #49854.
 [2009-10-15 16:43 UTC] danbrown@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.

Although PHP4 is not - and will never again be - officially supported, 
as it's been past its end-of-life for two years, the issue you 
reported would also exist for any version with two or more digits in 
any position.  As a result, it's been updated to use explode() (though 
not list(), as you'll see when the sources update).

However, while it may not be explicitly stated on the notes page, 
there is a level of common sense assumed - perhaps an error on our 
part - that those intelligent enough to engineer code will also be 
able to ascertain that a bug in documentation is, indeed, a bug.  The 
following line is in warning of this exact issue when submitting a 
user note:

"Bugs. Instead [report a bug] for this manual page to the bug 
database."

The [report a bug] string then links directly to this URL:

http://bugs.php.net/report.php?
bug_type=Documentation+problem&manpage=function.phpversion

By the above, it should be trivial to discover under which category 
the bug will be reported, and we hope that this will help you to not 
waste your time in the future, and so also assist in the wild-guessing 
about how we presently operate the websites.

Thank you very much for your report, and as stated, the changes will 
appear in the next documentation build.
 [2009-10-15 16:56 UTC] clancyhood at gmail dot com
Fair enough, thanks Dan.  Sorry, I was in a dreadfully p*ssy mood, not best for writing bug reports :) I guess I was just annoyed at having to write it again (read: having note deleted) since while it was fairly trivial it still seemed important.

Thanks for fixing it up.

Clancy
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 00:00:02 2026 UTC