
批改狀態(tài):合格
老師批語:
代碼塊
Test.php
<?php/** * Class Test * 類的實例化 * 類的靜態(tài)屬性和靜態(tài)方法 */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);
效果
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號