用你这方法不行。Warning: Missing argument 1 for test::test(), called in C:\wamp\www\zhebo\index.php on line 24 and defined in C:\wamp\www\zhebo\x\init.php on line 170
class test{ function test(){ object::hello(); } }class object{ Public static function hello(){ echo "hello"; } }
$instest = new test();
$insobject = new object();
$instest->test($insobject);
}class test{
function test($insobject){
$insobject->hello();
}
}class object{
function hello(){
echo "hello";
}
}
一般从设计的角度来说,采用继承的方式,会更好。
只是个变量作用域的问题!
class test{
function test(){
$insobject->hello();
}
}
中 $insobject 是局部变量,并且也没有赋值。
当然也就没有 hello 方法了
function test(){
global $insobject;
$insobject->hello();
}
}
这样每个函数里 都要申明不是很复杂么!!没有什么委婉一点的么
function test(){
object::hello();
}
}class object{
Public static function hello(){
echo "hello";
}
}