From 6cf9bf59b9ee90cdb06ff47c7363f7c90080572a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A6=E6=B0=B8=E9=9F=AC?= <1795535399@qq.com> Date: Tue, 17 May 2022 21:27:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...42\345\220\221\345\257\271\350\261\241.md" | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 "\351\237\246\346\260\270\351\237\254/20220517-\351\235\242\345\220\221\345\257\271\350\261\241.md" diff --git "a/\351\237\246\346\260\270\351\237\254/20220517-\351\235\242\345\220\221\345\257\271\350\261\241.md" "b/\351\237\246\346\260\270\351\237\254/20220517-\351\235\242\345\220\221\345\257\271\350\261\241.md" new file mode 100644 index 0000000..18fd024 --- /dev/null +++ "b/\351\237\246\346\260\270\351\237\254/20220517-\351\235\242\345\220\221\345\257\271\350\261\241.md" @@ -0,0 +1,140 @@ +```php +brand=$brand; + $this->price=$price; +} + /** + * @return mixed + */ + public function getPrice() + { + return $this->price; + } + + /** + * @param mixed $price + * @return automobile + */ + public function setPrice($price) + { + $this->price = $price; + return $this; + } + + /** + * @return mixed + */ + public function getBrand() + { + return $this->brand; + } + + /** + * @param mixed $brand + * @return automobile + */ + public function setBrand($brand) + { + $this->brand = $brand; + return $this; + } + +} + +//2、在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 +class roadster extends automobile { + function __construct($brand, $price){ + parent::__construct($brand, $price); + } +} + +//3、定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法 +class a { + public $aa; + public $bb; + public $cc; + protected $b; + protected $c; + protected $d; + private $ab; + private $bc; + private $cd; + public function w1(){ + + } + public function w2(){ + + } + public function w3(){ + + } + protected function w4(){ + + } + protected function w5(){ + + } + protected function w6(){ + + } + private function w7(){ + + } + private function w8(){ + + } + private function w9(){ + + } +} + +$a=new automobile("布加迪","100"); +$b=new roadster("劳斯莱斯","999"); +echo $a->getBrand().$a->getPrice(); +echo "
"; +echo $b->getBrand().$b->getPrice(); +``` + +```php +/* + 面向对象 不支持方法重载,不能同时写有参,无参构造器 ALT+回车(get set) + var public private protected 修饰 +const 常量 +static 静态属性,所有对象共享,属于类的 +类名::方法名(); + -> 连接 + function __construct(){ 构造方法 + + } + + function __destruct(){ 析构方法 + + } + unset(); 销毁 + isset(); 判断变量存在与否 + +extends 继承 +play +self 表示当前类 +parent 父类 +parent:: + +abstract 抽象类 + +interface 接口 +implements 实现接口 + + +instanceof 判断方法 + + + */ +``` \ No newline at end of file -- Gitee