继承引入参数
name = $name; $this->age = $age; $this->time=date("Ymd"); } /** * @return mixed */ public function hello() { echo $this->time; }}class B extends A{ private static $name = '123'; private static $age = 12; public function __construct() { parent::__construct(self::$name, self::$age); }}$obj = new B();echo $obj->hello();
实例化引入重写
name = $name; $this->age = $age; $this->time=date("Ymd"); } /** * @return mixed */ public function hello() { echo $this->time; }}class B{ public static $a; public function __construct() { $name='jack'; $age=23; self::$a=new A($name,$age); } public function test(){ echo self::$a->time; }}$obj = new B();$obj->test();