日期:2014-05-17 浏览次数:20423 次
<?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; //访问属性要这样
}
}