Note that there are some explanatory texts on larger screens.

plurals
  1. PONested output buffering with external class dependencies [please help]
    primarykey
    data
    text
    <p>Thanks in advance for any and all advice.</p> <p>I have one file (content file) where an array is created like so:</p> <pre><code>$config['plugins']['BannerRotate'] = array( 'container' =&gt; 'abroadView', 'arrows' =&gt; true, 'auto' =&gt; true, 'speed' =&gt; '15000', 'width' =&gt; '300px', 'height' =&gt; '220px', 'tags' =&gt; 'slider' ); </code></pre> <p>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).</p> <p>That array is then used by the template system to generate a new object like so:</p> <pre><code>if(isset($GLOBALS['config']['plugins'])){ foreach($GLOBALS['config']['plugins'] as $plugin =&gt; $ary){ $$plugin = new Ispweb_Plugindaemon(CURRENTSRV,getcwd().'/', $GLOBALS['config']['plugins'][$plugin],$plugin); // this statement is simply the result of the eval statement below } } </code></pre> <p>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).</p> <p>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.</p> <p>Here is what I'm doing within the templating system to buffer the content file (and create the object(s)):</p> <pre><code>ob_start(); include $core_page_content; // the content file (where initial array is) if(isset($GLOBALS['config']['plugins'])){ foreach($GLOBALS['config']['plugins'] as $plugin =&gt; $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 =&gt; $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(); </code></pre> <p>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?</p> <p>What can I do?</p> <p>P.S. I know the setup is not ideal. There's nothing I can do about that.</p> <p>Thanks!</p> <p><strong>TL;DR</strong> 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.</p> <p>Additional Notes:</p> <p>File B:</p> <pre><code>$config['plugins']['BannerRotate'] = array( 'container' =&gt; 'abroadView', 'arrows' =&gt; true ); // page content (XHTML) </code></pre> <p>File A:</p> <pre><code>ob_start(); $core_page_content = 'file_b'; include $core_page_content; if(isset($config['plugins'])){ foreach($config['plugins'] as $plugin =&gt; $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'; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload