Note that there are some explanatory texts on larger screens.

plurals
  1. POOO PHP Functions
    primarykey
    data
    text
    <p>I am fairly new to PHP OOP, the problem that I am have is that I can't wrap my head around the follow layout of my script:</p> <ul> <li>main class is set which sets up the page and extends a mysql class and creates the database connect through the __construct</li> <li>within main class i run a public function which includes() a file and accesses a function that is in that include file</li> <li>within the function that is in the included file i can't seem to access the main class through neither the actual global variable or use $this->blah</li> </ul> <p>does anyone have any pointers or direction. i tried googling it but couldn't come across anything remotely close to what i was trying to do.</p> <p>it is started with: - works</p> <pre><code>$gw = new GWCMS(); </code></pre> <p>then inside of the _construct of GWCMS() which GWCMS extends mySQL - works</p> <pre><code>parent::__construct(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME); $this-&gt;build(); </code></pre> <p>then it calls build() - works</p> <pre><code>public function build(){ ... $page['content'] = $this-&gt;plugins($page['content']); ... $output = $this-&gt;output($theme,$page); echo eval('?&gt;' . $output); } </code></pre> <p>which calls plugins() - we start having problems</p> <pre><code>public function plugins($content){ $x = 0; if ($handle = opendir(STOCKPLUGINPATH)) { while (false !== ($entry = readdir($handle))) { if(is_dir(STOCKPLUGINPATH . $entry . '/') &amp;&amp; $entry != '.' &amp;&amp; $entry != '..'){ if(file_exists(STOCKPLUGINPATH . $entry . '/inc.php')){ include(STOCKPLUGINPATH . $entry . '/inc.php'); $content = do_shortcode($content); } } } closedir($handle); } return $content; } </code></pre> <p>the previous code includes inc.php which lists the files to be include:</p> <pre><code>include(STOCKPLUGINPATH . 'Test/test.php'); </code></pre> <p>test.php includes the list of functions. the do_shortcode above accesses the functions without a problem and does the work however i need the following function which is in the test.php to access the $gw->fetchAssoc(); which fetchAssoc is in the parent of gwcms</p> <pre><code>function justtesting2($attr){ $config = $gw-&gt;fetchAssoc("Select * from gw_config"); foreach($config as $c){ echo $c['value']; } } </code></pre> <p>when i run the script i get </p> <pre><code>Fatal error: Call to a member function fetchAssoc() on a non-object in /home/globalwe/public_html/inhouse/GWCMS/gw-includes/plugins/Test/test.php on line 9 </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.
 

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