2009-01-21 52 views
1

即使调用了对象,我也会收到“在第35行的page.class.php中的非对象上调用成员函数process_data()”。PHP中可能存在的多实例对象问题

这里是表示对象在index.php提取被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; 

它然后转到Process类

 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(); 

这是在这一点上PHP是引发错误。该module.php文件的内容如下:

class module { 

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

我已经试过实例声明移到第二粘贴代码中,而是产生更多的错误,因为类“模块”在随后的使用要求一些“模板”类也是如此 - 所以相同的问题发生在更后面。

我怎么会错她,或完全失踪,我敢肯定它是后者,但我真的需要帮助。谢谢

回答

0

它看起来好像当你试图调用对象方法时变量$ module不在范围内。你可以在$ module-> process_data(“module_”。$ page)之前尝试var_dump($ module)。这个功能的结果是什么?快速解决方案可能会声明$ module global,但全局变量不是一个好主意(但可以检查它是否有效)。

+0

var_dump确实返回null。我以前尝试过全球,这并没有解决问题。 我已经阅读了关于对象和类的文档,但这并不是启发我;当然没有跨多个文件/类的问题。 – jakeisonline 2009-01-21 16:45:07