向构造方法中传弟对象变量
时间:2007-06-15 来源:liuxingyuyuni
实现对对功能的扩展,例如可传如模板,ajax等
?php
class Person
{
public $name = null;
public $age = 0;
private $money = 0;
private $otherObj = null;
public function __construct($name, $age, $money, $obj)
{
$this->name = $name;
$this->age = $age;
$this->money = $money;
$this->otherObj = $obj;
}
public function getObj()
{
return $this->otherObj;
}
}
class Test
{
public $hi = 'hi';
public function sayHello()
{
echo 'hello!~';
}
}
$test = new Test();
$per = new Person('小破孩',24, 1000000, $test);
$per->getObj()->sayHello();
?>
相关阅读 更多 +
排行榜 更多 +