Question

I'm getting a "Call to a member function process_data() on a non-object in page.class.php on line 35" even though the object has been called.

Here is the index.php extraction showing the object being instantised

// require our common files
require("modules/module.php");
require("registry/objects/datetime.class.php");
require("registry/objects/page.class.php");


// load in all the objects
$datetime = new dateandtime;
$page = new page;
$module = new module;

It then passes to the Process class

        require("template.class.php");
        $template = new template($php_path . "controllers/themes/adm/" . $page . ".html");

        // Place in both commonly used language and page specific language
        $template->language($php_path . "controllers/language/en/adm/common.php");
        $template->language($php_path . "controllers/language/en/adm/" . $page . ".php");

        // Tell the page's module to load in data it needs
        $module->process_data("module_" . $page);

        // Output the final result
        $template->output();

It's at this point PHP is throwing the error. The contents of the module.php file is as follows

class module {

    public function process_data ($child) {
        require($child . ".php");
        read_data();
        return true;
    }
}

I've tried moving the instance declaration to within the second pasted code, but that generates more errors, because the class that "module" calls in then uses some of the "template" classes as well - so the same issue occurs just further down the line.

What am I getting wrong her, or completely missing, I'm sure it's the latter but I really need help here. Thanks

Was it helpful?

Solution

It looks to me as if variable $module was not in the scope when you try to call object method. Could you try var_dump($module) before $module->process_data("module_" . $page). What is the result of this function? Quick solution may be declaring $module global, but globals are not a very good idea anyway (but you may check if it works).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top