cvs: phpdoc /en/reference/info/functions phpversion.xml
| From: | Kalle Sommer Nielsen | Date: | Wed, 13 May 2009 08:06:26 +0000 |
| Subject: | cvs: phpdoc /en/reference/info/functions phpversion.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4009@lists.php.net to get a copy of this message | ||
kalle Wed May 13 08:06:26 2009 UTC
Modified files:
/phpdoc/en/reference/info/functions phpversion.xml
Log:
New example for PHP_VERSION_ID
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/info/functions/phpversion.xml?r1=1.9&r2=1.10&diff_format=u
Index: phpdoc/en/reference/info/functions/phpversion.xml
diff -u phpdoc/en/reference/info/functions/phpversion.xml:1.9
phpdoc/en/reference/info/functions/phpversion.xml:1.10
--- phpdoc/en/reference/info/functions/phpversion.xml:1.9 Wed Jun 20 22:24:48 2007
+++ phpdoc/en/reference/info/functions/phpversion.xml Wed May 13 08:06:26 2009
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.9 $ -->
+<!-- $Revision: 1.10 $ -->
<refentry xml:id="function.phpversion" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>phpversion</refname>
@@ -62,6 +62,47 @@
</programlisting>
</example>
</para>
+ <para>
+ <example>
+ <title><constant>PHP_VERSION_ID</constant> example and usage</title>
+ <programlisting role="php">
+<![CDATA[
+<?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}));
+}
+
+// PHP_VERSION_ID is defined as a number, where the higher the number
+// is, the newer a PHP version is used. Its defined as used in the above
+// expression:
+//
+// $version_id = $major_version * 10000 + $minor_version * 100 + $release_version;
+//
+// Now with PHP_VERSION_ID we can check for features this PHP version
+// may have, this doesn't require to use version_compare() everytime
+// you check if the current php version may not support a feature.
+//
+// For example, we may here define the PHP_VERSION_* constants thats
+// not available in versions prior to 5.2.7
+
+if(PHP_VERSION_ID < 50207)
+{
+ define('PHP_MAJOR_VERSION', $version{0});
+ define('PHP_MINOR_VERSION', $version{2});
+ define('PHP_RELEASE_VERSION', $version{4});
+
+ // and so on, ...
+}
+?>
+]]>
+ </programlisting>
+ </example>
+ </para>
</refsect1>
<refsect1 role="notes">
@@ -69,7 +110,9 @@
<note>
<para>
This information is also available in the predefined constant
- <constant>PHP_VERSION</constant>.
+ <constant>PHP_VERSION</constant>. More versioning information
+ is available using the <constant>PHP_VERSION_*</constant>
+ constants.
</para>
</note>
</refsect1>