Blogger Information
Blog 41
fans 2
comment 0
visits 29226
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php之类与继承
月光下,遗忘黑暗
Original
708 people have browsed it

代码块

Test.php

<?php/** * Class Test * 类的实例化 * 类的静态属性和静态方法 */class Test{//    抽象属性    private $name;    public static $username = '汤唯';    public function __construct($name,$username){        $this->name=$name;        self::$username=$username;    }    public function hello(){        echo "hello".$this->name."<hr>";    }    public static function hi(){        return "333<hr>";    }}Test::$username='321';$hello = new Test('miejue','汤唯');$hello->hello();echo Test::hi();

autoload.php

<?php/** * 类的自动加载 */spl_autoload_register(function ($class){    require $class.'.php';});

Extend.php

<?php/** * 类的继承 * 类方法的重写 * 类方法的扩展 */require 'autoload.php';class Extend extends Test{    public function __construct($a, $b)    {        parent::__construct($a, $b);    }    public function haha(){        echo '123'."<hr>";    }}$haha = new Extend('3','2');$haha->haha();$haha->hello();var_dump($haha instanceof Test);

效果

Correcting teacher:灭绝师太灭绝师太

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