test();class test{var $testVa">
时间:2021-07-01 10:21:17 帮助过:10人阅读
$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; //访问属性要这样
}
}