Search code examples
phpfirebugfirephp

Firephp, class file and 'Undefined variable'


this is a very dumb question but i have no php pal i can fall back to, sad me ;-)

So i have this setup, i have just installed firephp:

/lib/firephp.php   // firephp standard library
/lib/data.php      // a php class file of my own
        |
        |-> Class Data {}   // this is the class
                  function something() { $firephp->log('whatever'); }
pre.php            // here i initialize firephp
show_data.php      // i show data from the database here


---
pre.php
---
require_once($_SERVER['DOCUMENT_ROOT'] . '/intranet/lib/firephp.php');
ob_start();
$firephp = FirePHP::getInstance(true);

---
show_data.php
---
include('pre.php')
include('lib/data.php')
$c = new Data
$c->something()

And i get this: Notice: Undefined variable: firephp in show_data.php

TL;DR I initialize firephp in an include file, then include my class file, when i try to call it from inside the class it isn't able to read $firephp var...

Any tips, scolding or whatever you can help me is appreciated.


Solution

  • I found a good way to do this:

    In pre.php i created a function that creates $firephp object and then i just call that in show_data.php

    ---
    pre.php
    ---
    require_once($_SERVER['DOCUMENT_ROOT'] . '/intranet/lib/firephp.php');
    ob_start();
    
    function mylog($var, $other = '') {
        $firephp = FirePHP::getInstance(true);
        $firephp->log($var, $other);
    }
    
    
    ---
    show_data.php
    ---
    include('pre.php')
    include('lib/data.php')
    mylog('whatever');
    

    This works!