【发布时间】:2017-11-14 18:20:03
【问题描述】:
我想在类方法中调用一个函数,我创建了这个脚本,但不能正常工作?
致命错误:在第 12 行的 /.../.../index.php 中,在 null 上调用成员函数 function2()
public static function table($name_t, callable $callback){
self::databaseConnection();
try {
$matches = array(
.....
);
function engine($var){
Gaia::$engine__ = $var[0];
}
$eng = new Table_call;
echo $eng;
$callback($matches);
if(isset(self::$s)){
//self::$instance->exec("CREATE TABLE IF NOT EXISTS ".$name_t."( ".trim(self::$s,',')." ) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
echo "Dump Success!<br> ".self::$engine__ ;
}
//return $bgj;
} catch (Exception $e) {
self::$instance = null;
echo ("Oh noes! There's an error in the query: ". $e);
}
}
类文件 2
class Table_call extends Gaia{
public function __call($name,$arg){
call_user_func($name,$arg);
}
}
索引文件
Gaia::table('test', function($table){
$table['autoIncrement']('id');
})->engine('MyISAM');
我怎样才能以这种方式添加功能??
" ->function2('hello') "?
【问题讨论】:
-
静态函数需要通过
::请求,而非静态函数需要通过$this->请求。因此,在您的情况下,它将是self::function();,如果您将其设为非静态函数,它将是$this->function();。这会帮助你吗?一些额外的解释:stackoverflow.com/questions/1417438/… -
你能把整个 html 代码贴在你尝试回显 php 代码的地方吗?
-
好的抱歉,更新了。
-
你没有在方法中返回任何东西。通常,链接需要返回。
-
相关? Chaining Static Methods in PHP?(可能是骗子)
标签: php