PEAR logo

PHP_CompatInfo : The Definitive Guide

Chapter 8. Conditional Code Analysis

Table of Contents

Categories
How to catch them with web interface
How to catch them with CLI

Categories

As briefly introduced at end of Advanced detection chapter, we will learn now that there are 3 categories of conditional code that could give wrong result, if there are not catched properly.

These categories are :

  • function (cond_code = 1)

    A quick example:

    1. <?php
    2. if (function_exists('debug_backtrace')) {
    3.     $backtrace = debug_backtrace();
    4. } else {
    5.     $backtrace = false;
    6. }
    7. ?>
  • extension (cond_code = 2)

    A quick example:

    1. <?php
    2. if (extension_loaded('sqlite') == false) {
    3.     $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
    4.     dl($prefix . 'sqlite.' . PHP_SHLIB_SUFFIX);
    5.     echo 'SQLite version : ' . sqlite_libversion();
    6. }
    7. ?>
  • constant (cond_code = 4)

    A quick example:

    1. <?php
    2. if (defined('DATE_RSS') {
    3.     $date_format = DATE_RSS;
    4. } else {
    5.     $date_format = 'D, j M Y H:i:s O';
    6. }
    7. // will display something like "Sat, 26 Jul 2008 16:56:24 +0200"
    8. echo date($date_format, mktime(0, 0, 0, 7, 26, 2008));
    9. ?>
PHP_CompatInfo : The Definitive Guide v 1.8.0 : August 1, 2008