代码块
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);
效果