作业1:命名空间
实例
<?php namespace one; { class A { } (new \two\A())->show(); } namespace two; {class A { public function show() {echo __METHOD__;} } } //$a=new \two\A; //$a->show();
运行实例 »
点击 "运行实例" 按钮查看在线实例
作业2
实例
<?php namespace _0731; class A{ public $name; public $age; function __construct($name='李四',$age='50') { $this->name=$name; $this->age=$age; } function getInfo() { return '姓名:'.$this->name.' 年龄:'.$this->age; } } //$a=new A; //echo $a->getInfo(); class B extends A { public $work; public function __construct($work,$name = '李四', $age = '50') { parent::__construct($name, $age); $this->work=$work; } public function get() { return $this->name.'工作是'. $this->work; } } $b = new B('医生','张三',60); echo $b->get();
运行实例 »
点击 "运行实例" 按钮查看在线实例