views:

35

answers:

0

Thanks in advance for any and all advice.

I have one file (content file) where an array is created like so:

$config['plugins']['BannerRotate'] = array(
    'container'    =>    'abroadView',
    'arrows'    =>    true,
    'auto'        =>    true,
    'speed'        =>    '15000',
    'width'        =>    '300px',
    'height'    =>    '220px',
    'tags'      =>    'slider'
);

Which in turn is picked up by the so-called 'template system' and the layout is rendered with the page (and that array) as the argument (pretty standard).

That array is then used by the template system to generate a new object like so:

if(isset($GLOBALS['config']['plugins'])){
    foreach($GLOBALS['config']['plugins'] as $plugin => $ary){
        $$plugin = new Ispweb_Plugindaemon(CURRENTSRV,getcwd().'/',
        $GLOBALS['config']['plugins'][$plugin],$plugin);
        // this statement is simply the result of the eval statement below
    }
}

So then, since the name of the plugin in this case is BannerRotate, the object is $BannerRotate (variable variable). I'm doing this so I can have multiple plugin objects per page. This object is then used to call the jQuery plugin using member function $BannerRotate->getJS(). These member function calls are located WITHIN the templating system (IMPORTANT).

If I call a member function inside the same file as the initial array [OUTSIDE THE TEMPLATING SYSTEM] (the file that I'm buffering in order to create the object in the first place), everything dies. This doesn't make sense to me because if I var_dump($BannerRotate), I get a full object. However, say in that content file I do $BannerRotate->printNoscript(), everything disappears and the object is never created. I then get a fatal error that I'm calling a member function of a non-object. THAT IS THE PROBLEM.

Here is what I'm doing within the templating system to buffer the content file (and create the object(s)):

ob_start();
include $core_page_content; // the content file (where initial array is)
if(isset($GLOBALS['config']['plugins'])){
    foreach($GLOBALS['config']['plugins'] as $plugin => $ary){
        $ins[] = $plugin;
    }
}
$t = ob_get_contents();
ob_end_clean();
foreach($ins as $in){
    $a = CURRENTSRV; // a,b,c,d are just making the eval statement more clean
    $b = getcwd().'/';
    $c = array();
    foreach($GLOBALS['config']['plugins'][$in] as $key => $value){
        $c[$key] = $value;
    }
    $d = $in;
    eval("\$$in = new Ispweb_Plugindaemon(\"$a\",\"$b\",\$c,\"$d\");");
    echo $$in;
}
include $core_page_content;
$page_content = ob_get_contents();
ob_end_clean();

Does anyone know why I can access the object UNLESS I make a call to one of its member functions while inside the same file?

What can I do?

P.S. I know the setup is not ideal. There's nothing I can do about that.

Thanks!

TL;DR I'm creating an object in file A, with a variable from file B. I buffer file B to get the parameters to feed to file A, create the object, print it into another buffer and include file B in that buffer as well. If file B has a function call to the presumably created object, I get a fatal error: call to member function of non-object.

Additional Notes:

File B:

$config['plugins']['BannerRotate'] = array(
    'container'    =>    'abroadView',
    'arrows'       =>    true
);
// page content (XHTML)

File A:

ob_start();
$core_page_content = 'file_b';
include $core_page_content;
if(isset($config['plugins'])){
foreach($config['plugins'] as $plugin => $ary){
    $ins[] = $plugin;
}
ob_end_clean();
foreach($ins as $in){
    $$in = new Ispweb_Plugindaemon(CURRENTSRV,getcwd().'/',$config['plugins'][$in],$in);
}
include $core_page_content;
$page_content = ob_get_contents();
ob_end_clean();

// later on in the file
include 'top.htm';
include $page_content;
include 'bot.htm';