phpclassoopdebuggingfirephp

How do I use FirePHP in class.php files?


I'm just starting to learn OOP and PSR-4 autoload class files into my project. So far so good, but I rely on FirePHP. FirePHP works fine in my main scripts, but if I try to use FirePHP within a class file it doesn't work at all:

<?php namespace App\cmd;

class help
{
    public $test = "Test successful!";
    function __construct() {
        FB::info('HELP CLASS WAS CALLED!');
    }
}

I've tried all sorts of ways to try to make it work; trying to include fb.php and not trying to, adding ob_start(), with the error_handler and without. Nothing seems to work.

<?php namespace App\cmd;
ob_start();
require_once($_SERVER['DOCUMENT_ROOT'].'/FirePHPCore/fb.php');
set_error_handler('myErrorHandler');
set_exception_handler('myExceptionHandler');

function myErrorHandler($errno, $errstr, $errfile, $errline)
     {FB::error($errstr, 'Error number' . $errno . ' in ' . $errfile . ' at ' . $errline);}

function myExceptionHandler($errno, $errstr, $errfile, $errline)
    {FB::error($errstr, 'Exception number' . $errno . ' in ' . $errfile . ' at ' . $errline);}

class help
{
    public $test = "Test successful!";
    function __construct() {
        FB::info('HELP CLASS WAS CALLED!');
    }
}

The errors I get are:

PHP Parse error:  syntax error, unexpected 'FB' (T_STRING), expecting function (T_FUNCTION) in help.php 

Or

PHP Fatal error:  Class 'App\cmd\FB' not found in help.php

I must be doing something very stupid, can you tell me what I need to do to use FirePHP in class files?


Solution

  • The comments were correct, thanks. I just needed to namespace FirePHP correctly:

    <?php namespace App\cmd;
    use \FB as FB;
    class help
    {
        public $prop1 = "Command test successful!";
        function __construct() {
        FB::warn('HELP CLASS WAS CALLED!');
        }
    }