<?php header("Content-type:text/html;charset=utf-8"); class family { public $name; public $age; public function __construct() { echo "父類構造函數<br>"; } public function say() { echo "父類" . $this->name . "今年," . $this->age; } } class sun extends family { public $name; //與父類屬性同名將覆蓋父類的name public $age; public function __construct() { parent::__construct(); echo "子類構造函數<br>"; } public function sayddd() { $this->name = "ddddd"; $this->age = 222; $this->say(); } } $sun = new sun(); $reflect=new ReflectionClass($sun); //ReflectionObject 繼承了ReflectionClass $props=$reflect->getProperties(); //獲取類屬性 foreach ($props as $prop=>$value) { print $value->getName()."\n"; } $method=$reflect->getMethods(); //獲取方法 foreach ($method as $key=>$value) { print $value->getName()."\n"; }
輸出:php
父類構造函數
子類構造函數
name age __construct sayddd sayhtml