Blogger Information
Blog 35
fans 2
comment 0
visits 22727
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
继承和重载--2018年5月4日
小学僧的博客
Original
823 people have browsed it

截图:

0504.jpg

输出: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';
    }        
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post