Search code examples
phppearlibrariesfirephp

Check whether FirePHP is installed in PHP code


Is there any way to determine whether FirePHP is installed on the server (via PEAR)? I'd like to make possible logging in FirePHP but also not to crash the code for everyone without that tool.

The example, how I imagine it should work:

$message = "hello";
function log($message) {
    if (library_exists('FirePHPCore/fb.php')) {
        require_once('FirePHPCore/fb.php');
        ob_start();
        \FB::log($message);
    } else {
        SomeBoringLogger::log($message);
    }
}

I haven't found anything like my library_exists method. Is there anything like that in PHP?


Solution

  • @include_once('FirePHPCore/fb.php'); // Ignore any errors here, as we check for existance
    if (class_exists('FirePHP')) { // Do something after this
    

    http://php.net/manual/en/function.class-exists.php

    FirePHP uses FirePHP as its class name, so if it is available, that class should be defined


    For PHP 5.3.2 or later, use zerkms's suggestion:

    (!stream_resolve_include_path('FirePHPCore/fb.php')===FALSE)