<?php header("Content-Type:text/html;charset=utf-8;"); class car { public $pingpai; public $price; function __construct($pingpai, $price) { $this->pingpai = $pingpai; $this->price = $price; } function showCommon() { return "common"; } } class BMW extends car { function showCar() { return "我买了一辆:" . $this->pingpai . ",它花了我" . $this->price . "钱"; } } $bmw = new BMW("宝马", "50w"); $show = $bmw->showCar(); var_dump($show); var_dump($bmw->showCommon());
{ return $this->kw; } public function setBrNaVozdushniPernichinja($i) { $this->br_vozdushni_pernichinja = $i; } public function getBrNaVozdushniPernichinja() { return $this->br_vozdushni_pernichinja; } public function setModel($i) { $this->model = $i; } public function getModel() { return $this->model; } public function pali() { echo "brm brm brm!"; } } $bmw = new BMW(); $bmw->setModel('X5'); $bmw->setKw(400); $bmw->pali(); echo "<pre>"; print_r($bmw); echo "</pre>";
<?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ function __autoload($classes) { echo "I want to see : " . $classes; include_once $classes . ".php"; } $a = new BMW(); $a->sajjad();
public static function create($color) { $bmw = new BMW(); return $bmw->paintTo($color); }