From 6c782ba6b008dffb0da9af89d9c0ce4e37818a8e Mon Sep 17 00:00:00 2001 From: xushiheng <2363492796@qq.com> Date: Tue, 17 May 2022 22:05:01 +0800 Subject: [PATCH] 1 --- ...42\345\220\221\345\257\271\350\261\241.md" | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 "\345\276\220\350\257\227\346\201\222/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" diff --git "a/\345\276\220\350\257\227\346\201\222/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" "b/\345\276\220\350\257\227\346\201\222/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" new file mode 100644 index 0000000..89ac9b5 --- /dev/null +++ "b/\345\276\220\350\257\227\346\201\222/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" @@ -0,0 +1,162 @@ +```php +brand=$brand; + $this->price=$price; + } + function run(){ + echo "这辆车是:".$this->brand.",价格为:",$this->price; +} + + /** + * @return mixed + */ + public function getBrand() + { + return $this->brand; + } + + /** + * @param mixed $brand + */ + public function setBrand($brand) + { + $this->brand = $brand; + } + + /** + * @return mixed + */ + public function getPrice() + { + return $this->price; + } + + /** + * @param mixed $price + */ + public function setPrice($price) + { + $this->price = $price; + } + + +} +$aa =new Car("青桔","九镑十五便士"); +$aa->run(); +echo "
"; +//2、 在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 + +class SportsCar extends Car{ + function __construct($brand, $price) + { + parent::__construct($brand, $price); + } + function spe(){ + echo "这辆跑车为:".$this->getBrand().",价格为:".$this->getPrice(); + } +} +$bb = new SportsCar("美团","百万英镑"); +$bb->spe(); +echo "
"; + +//3、 定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +class san { + //一 + public $a1; + public $b1; + public $c1; + + function dog() + { + } + + function variety() + { + } + + function color() + { + } + //二 + protected $a2; + protected $b2; + protected $c2; + protected function dog2() + { + } + + protected function variety2() + { + } + + protected function color2() + { + } + //三 + private $a3; + private $b3; + private $c3; + + /** + * @return mixed + */ + public function getA3() + { + return $this->a3; + } + + /** + * @param mixed $a3 + */ + public function setA3($a3) + { + $this->a3 = $a3; + } + /** + * @return mixed + */ + public function getB3() + { + return $this->b3; + } + + /** + * @param mixed $b3 + */ + public function setB3($b3) + { + $this->b3 = $b3; + } + /** + * @return mixed + */ + public function getC3() + { + return $this->c3; + } + + /** + * @param mixed $c3 + */ + public function setC3($c3) + { + $this->c3 = $c3; + } + +} + + +``` + -- Gitee