diff --git "a/\351\231\210\351\233\205\346\245\240/20220510-php\347\254\254\344\270\200\347\253\240.php" "b/\351\231\210\351\233\205\346\245\240/20220510-php\347\254\254\344\270\200\347\253\240.md" similarity index 100% rename from "\351\231\210\351\233\205\346\245\240/20220510-php\347\254\254\344\270\200\347\253\240.php" rename to "\351\231\210\351\233\205\346\245\240/20220510-php\347\254\254\344\270\200\347\253\240.md" diff --git "a/\351\231\210\351\233\205\346\245\240/20220511-php\347\254\254\344\272\214\347\253\240.php" "b/\351\231\210\351\233\205\346\245\240/20220511-php\347\254\254\344\272\214\347\253\240\350\277\220\347\256\227\347\254\246.md" similarity index 100% rename from "\351\231\210\351\233\205\346\245\240/20220511-php\347\254\254\344\272\214\347\253\240.php" rename to "\351\231\210\351\233\205\346\245\240/20220511-php\347\254\254\344\272\214\347\253\240\350\277\220\347\256\227\347\254\246.md" diff --git "a/\351\231\210\351\233\205\346\245\240/20220516-php\347\254\254\344\270\211\347\253\240.php" "b/\351\231\210\351\233\205\346\245\240/20220516-php\347\254\254\344\270\211\347\253\240\346\225\260\347\273\204.md" similarity index 100% rename from "\351\231\210\351\233\205\346\245\240/20220516-php\347\254\254\344\270\211\347\253\240.php" rename to "\351\231\210\351\233\205\346\245\240/20220516-php\347\254\254\344\270\211\347\253\240\346\225\260\347\273\204.md" diff --git "a/\351\231\210\351\233\205\346\245\240/20220517-php\347\254\254\345\233\233\347\253\240\351\235\242\345\220\221\345\257\271\350\261\241.md" "b/\351\231\210\351\233\205\346\245\240/20220517-php\347\254\254\345\233\233\347\253\240\351\235\242\345\220\221\345\257\271\350\261\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..d19bcd0e3af0aa46cc5b0685bfbde1a59bd88a0a --- /dev/null +++ "b/\351\231\210\351\233\205\346\245\240/20220517-php\347\254\254\345\233\233\347\253\240\351\235\242\345\220\221\345\257\271\350\261\241.md" @@ -0,0 +1,126 @@ +````php +//1、 写一段代码,定义一个汽车类,有品牌与价格两种属性。并为类实例化对象,为对象的属性赋值并引用。 +//2、 在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 + +class car{ + private $brand; + private $price; + + + function __construct($brand,$price){ + $this->brand=$brand; + $this->price=$price; + }//魔术构造 + +// function cars(){ +// echo $this->brand.$this->price; +// } + + + /** + * @return mixed + */ + public function getPrice() + { + return $this->price; + } + + /** + * @param mixed $price + */ + public function setPrice($price) + { + $this->price = $price; + } + + /** + * @return mixed + */ + public function getBrand() + { + return $this->brand; + } + + /** + * @param mixed $brand + */ + public function setBrand($brand) + { + $this->brand = $brand; + } + +} + + +$masha=new car("玛莎拉蒂",133333); + +$a="我有一辆豪车,它是一辆".$masha->getBrand().",它的价格为".$masha->getPrice()."刀"; +echo $a; +echo "\t\t"; + + +class paocar extends car{ + function __construct($brand, $price) + { + parent::__construct($brand, $price); + } + + function run(){ + echo "我有一辆跑车它会跑,它是一辆"; + } + +} + + +$fll=new paocar("法拉利",223333); + +echo $fll->run(); +echo $fll->getBrand().",它的价格为:".$fll->getPrice()."刀"; +```` + + + + + + + + + + + +```php +//3、 定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +class dog{ + public $name; + public $age; + public $sex; + + protected $color; + protected $run; + protected $sleep; + + private $vars; + private $length; + private $character; + + public function eat(){ + echo "它吃狗粮"; + } + public function drunk(){ + echo "它喝牛奶"; + } + public function la(){ + echo "它会自己上厕所"; + } + + + protected function color(){} + protected function run(){} + protected function sleep(){} + + private function vars(){} + private function length(){} + private function character(){ + } +} +``` \ No newline at end of file