PHP对象编程问题,Call to a member function hello() on a non-object
<?php
$instest = new test();
$insobject = new object();
$insobject->objectValue = "final";
$instest->test();
class test{
var $testValue = "testValueins";
function test(){
print_r($insobject);
$insobject->hello();
}
}
class object{
var $objectValue = "original";
function hello(){
echo $objectValue;
}
}
?>
$insobject = new object();object Object ( [objectValue] => final ) final
$insobject->objectValue = "final";
$instest = new test($insobject);
//$instest->test(); 这是构造函数,一般不这样调用
class test{
var $testValue = "testValueins";
function test($insobject){
print_r($insobject);
$insobject->hello();
}
}
class object{
var $objectValue = "original";
function hello(){
echo $this->objectValue; //访问属性要这样
}
}