From 086ee5a06dc2a9b8273574c8c883efdbaa815765 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 28 Jul 2009 14:42:12 +0000 Subject: add is_php() to Common.php --- system/codeigniter/Common.php | 23 +++++++++++++++++++++++ user_guide/changelog.html | 1 + user_guide/general/common_functions.html | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 340be2454..39005f602 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -29,6 +29,29 @@ // ------------------------------------------------------------------------ +/** +* Determines if the current version of PHP is greater then the supplied value +* +* Since there are a few places where we conditionally test for PHP > 5 +* we'll set a static variable. +* +* @access public +* @return bool +*/ + function is_php($version = '5.0.0') + { + static $_is_php; + + if ( ! isset($_is_php[$version])) + { + $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; + } + + return $_is_php[$version]; + } + +// ------------------------------------------------------------------------ + /** * Tests for file writability * diff --git a/user_guide/changelog.html b/user_guide/changelog.html index 7bf5028d3..1de9effe6 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -92,6 +92,7 @@ SVN Revision:

  • Modified show_error() to allow sending of HTTP server response codes.
  • Modified show_404() to send 404 status code, removing non-CGI compatible header() statement from error_404.php template.
  • Added set_status_header() to the Common functions to allow use when the Output class is unavailable.
  • +
  • Added is_php() to Common functions to facilitate PHP version comparisons.

  • diff --git a/user_guide/general/common_functions.html b/user_guide/general/common_functions.html index 980a5a969..1f4394424 100644 --- a/user_guide/general/common_functions.html +++ b/user_guide/general/common_functions.html @@ -59,6 +59,18 @@ Auto-loading Resources

    CodeIgniter uses a few functions for its operation that are globally defined, and are available to you at any point. These do not require loading any libraries or helpers.

    +

    is_php('version_number')

    + +

    is_php() determines of the PHP version being used is greater than the supplied version_number.

    + +if (is_php('5.3.0'))
    +{
    +    $str = quoted_printable_encode($str);
    +}
    + +

    Returns boolean TRUE if the installed version of PHP is equal to or greater than the supplied version number. Returns FALSE if the installed version of PHP is lower than the supplied version number.

    + +

    is_really_writable('path/to/file')

    is_writable() returns TRUE on Windows servers when you really can't write to the file as the OS reports to PHP as FALSE only if the read-only attribute is marked. This function determines if a file is actually writable by attempting to write to it first. Generally only recommended on platforms where this information may be unreliable.

    -- cgit v1.2.3-24-g4f1b