<?php
class Door
{
public function __construct()
{
}
public function test(){
echo "welocme";
}
}
$obj=new Door();
get_data();
function get_data(){
$obj->test();
}
$ obj-&GT;测试();在功能之外工作,但我需要内部功能。我无法访问函数show error
中的对象Fatal error: Call to a member function test()
答案 0 :(得分:1)
尝试这样:它可能会有效..
如果你在函数中使用任何外部变量,则取消为global $use_variable_name
。现在你可以理解......
function get_data(){
global $obj;
$obj->test();
}
另一种更好的方法:
get_data($obj);// call this way...
function get_data($object){
$object->test();
}