2012-07-30 108 views
0

如果你看看它明确定义和公开的代码。为什么我会遇到致命错误:调用未定义的函数prep_connections()?

<?php 
class Config { 
    public function prep_connections($collection){ 

    } 

    public function get_connctions(){ 
    require_once('readfile.php'); 

    $reader = new Readfile(); 

    $collections = json_decode($reader->read("../../config/database.cfg")); 

    foreach($collections as $collection){ 
     prep_connections($collection); 
    } 
    } 
} 

$config = new Config(); 
$connections = $config->get_connctions(); 
+0

有一个在你发布的链接没有代码。 – 2012-07-30 14:01:59

+0

您可以始终手动缩进代码 - 只需确保发布相关代码而不是小说。 – Matt 2012-07-30 14:04:59

回答

1

你需要通过$this调用它,告诉它是在同一个/这个类

$this->prep_connections($collection); 
+0

凉豆它工作! – 2012-07-30 14:06:19

0

prep_connections()未定义。您必须为includerequire定义您的函数才能使其工作的文件。

1

要调用prep_connections外的类范围。

您正打算致电Config->prep_connections();但实际上你只是拨打\prep_connections();

你应该换线你:

prep_connections($collection); 

要:

$this->prep_connections($collection); 

或者

self::prep_connections($collection); 
相关问题