diff --git "a/\346\242\201\350\243\225/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" "b/\346\242\201\350\243\225/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..7085ef8bb2c6e4462f7c9b5f19b60b25c862930e --- /dev/null +++ "b/\346\242\201\350\243\225/20220517-php\351\235\242\345\220\221\345\257\271\350\261\241.md" @@ -0,0 +1,179 @@ +```php +brand=$brand; + $this->money=$money; +} + +function che(){ + echo $this->money."的".$this->brand; +} + +/** + + * @return mixed + */ + public function getMoney() + { + return $this->money; + } + +/** + + * @param mixed $money + */ + public function setMoney($money): void + { + $this->money = $money; + } + +/** + + * @return mixed + */ + public function getBrand() + { + return $this->brand; + } + +/** + + * @param mixed $brand + */ + public function setBrand($brand): void + { + $this->brand = $brand; + } + +} +$a = new Car("法拉利","100w"); +$a->che(); + +echo "
"; + +//2、 在上例的基础上为汽车类定义一个子类——跑车类。为子类实例化对象并访问父类的属性。 +class pc extends Car{ + function __construct($brand, $money) + { + parent::__construct($brand, $money); + } + function run(){ + echo parent::getBrand()."跑得很快!它要".parent::getMoney(); + } +} +$b=new pc("奥迪",400000); +$b->run(); + +//3、 定义一个类,分别定义3个公共的属性和方法,3个受保护的属性和方法,3个私有属性和方法。 +class lei{ + public $p; + public $o; + public $k; + public function v(){ + } + public function b(){ + } + public function n(){ + +} +protected $r; +protected $d; +protected $t; +protected function f(){ + +} +protected function g(){ + +} +protected function s(){ + +} + +private $h; +private $j; +private $i; +/** + + * @return mixed + */ + public function getH() + { + return $this->h; + } + +/** + + * @param mixed $h + */ + public function setH($h): void + { + $this->h = $h; + } + +/** + + * @return mixed + */ + public function getJ() + { + return $this->j; + } + +/** + + * @param mixed $j + */ + public function setJ($j): void + { + $this->j = $j; + } + +/** + + * @return mixed + */ + public function getI() + { + return $this->i; + } + +/** + + * @param mixed $i + */ + public function setI($i): void + { + $this->i = $i; + } + +private function h(){ + +} +private function j(){ + +} +private function i(){ + +} + + + +} +``` +