Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8146739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:06:18+00:00 2026-06-06T14:06:18+00:00

I am fairly new to PHP OOP, the problem that I am have is

  • 0

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:

  • main class is set which sets up the page and extends a mysql class and creates the database connect through the __construct
  • within main class i run a public function which includes() a file and accesses a function that is in that include file
  • 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

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.

it is started with: – works

$gw = new GWCMS();

then inside of the _construct of GWCMS() which GWCMS extends mySQL – works

parent::__construct(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
$this->build();

then it calls build() – works

public function build(){
   ...
   $page['content'] = $this->plugins($page['content']);
   ...
   $output = $this->output($theme,$page);
   echo eval('?>' . $output);
}

which calls plugins() – we start having problems

public function plugins($content){
   $x = 0;
   if ($handle = opendir(STOCKPLUGINPATH)) {
      while (false !== ($entry = readdir($handle))) {
         if(is_dir(STOCKPLUGINPATH . $entry . '/') && $entry != '.' && $entry != '..'){ 
            if(file_exists(STOCKPLUGINPATH . $entry . '/inc.php')){
               include(STOCKPLUGINPATH . $entry . '/inc.php');
               $content = do_shortcode($content);
            }
         }
      }
      closedir($handle);
   }
   return $content;
}

the previous code includes inc.php which lists the files to be include:

include(STOCKPLUGINPATH . 'Test/test.php'); 

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

function justtesting2($attr){
   $config = $gw->fetchAssoc("Select * from gw_config");
   foreach($config as $c){
      echo $c['value'];
   }
}

when i run the script i get

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:06:19+00:00Added an answer on June 6, 2026 at 2:06 pm

    Writing OOP code means restructuring to avoid that mess of files and functions dropped into what ever files and god knows what not.

    Try to rely on writing a class that models the behavior you want to achieve. The class should contain property values that carry data for you and methods that help the class behave like the thing you’re modeling it to.

    To answer your question:

    class MyClass {
        public $my_property = 4;
        public function MyMethod() {
            include('file.php');
        }
        public function MyOtherMethod() {
            $this; // is accessible because MyOtherMethod
                   // is a method of class MyClass
        }
    }
    
    // contents of file.php
    
    $variable = 3;
    
    function MyFunction($parameter) {
        global $variable; // is accessible
        $parameter; // is accessible
        $this // is not accessible because it was
              // not passed to MyFunction as a parameter
              // nor was it declared as a global variable
    
        // MyFunction is not a method of class MyClass,
        // there is no reason why $this would be accessible to MyFunction
        // they are not "related" in any OOP way
        // this is called variable scoping and/or object scoping
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to PHP, but have managed to set up a script that
I'm fairly new to PHP so I have a small problem as I'm learning:
I'm fairly new to php and I'm using a script that creates a function
I'm trying to learn how to use oop in php. I'm also fairly new
I am fairly new to PHP, but have applied my previous knowledge of programming,
I've got a really simple problem but I just can't sort it, fairly new
I'm fairly new to HTML, PHP, CSS and Javascript. I do have a bit
I'm fairly new to OOP in PHP, I've made a couple of basic scripts
I am fairly new to php and have not figured out how I would
I have a Highchart scatter chart that plots data calculated using a PHP script.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.