我在使用MyClass::function();
的方式调用方法时遇到了问题,但无法弄清原因。以下是一个例子(顺便提一下,我正在使用Kohana框架):
class Test_Core
{
public $var1 = "lots of testing";
public function output()
{
$print_out = $this->var1;
echo $print_out;
}
}
我尝试使用以下代码进行调用,但返回的结果是$var1未定义:
Test::output()
然而,这样做很好:
$test = new Test();
$test->output();
我通常使用这种方式来调用对象,而不是使用“new Class”样式,但我不知道为什么它不起作用。