截图:
输出:test.php
实例
<?php spl_autoload_register(function($className){ require $className.'.php'; }); $iphone = new iphone('reitna','ios', '11.3',true,true); echo 'display: '.$iphone->display.'<br>'; echo 'os: '.$iphone->os.'<br>'; echo 'version: '.$iphone->version. '<br>'; echo 'chip:'.($iphone->chip?'yes':'no').'<br>'; echo 'soft:'.($iphone->soft?'yes':'no').'<br>'; echo $iphone->movie().'<br>'; echo $iphone->game().'<br>';
运行实例 »
点击 "运行实例" 按钮查看在线实例
父类:mac.php
实例
<?php class Mac { protected $display; protected $os; protected $version; public function __construct($display,$os,$version) { $this->display = $display; $this->os = $os; $this->version = $version; } public function movie() { return 'movie'; } }
运行实例 »
点击 "运行实例" 按钮查看在线实例
子类:iphone.php
实例
<?php class iphone extends Mac { public function __get($name) { return $this->$name; } private $chip = false; private $soft = false; public function __construct($display,$os,$verison,$chip,$soft) { parent::__construct($display, $os, $verison); $this->chip = $chip; $this->soft = $soft; } public function game() { return 'play games'; } public function movie() { return parent::movie().' and coding'; } }
运行实例 »
点击 "运行实例" 按钮查看在线实例