除錯資訊()
當轉儲物件以獲取應顯示的屬性時,
var_dump()
會呼叫此方法。如果未在物件上定義該方法,則將顯示所有公共屬性,受保護屬性和私有屬性。 - PHP 手冊
class DeepThought {
public function __debugInfo() {
return [42];
}
}
Version <= 5.6
var_dump(new DeepThought());
以上示例將輸出:
class DeepThought#1 (0) {
}
Version >= 5.6
var_dump(new DeepThought());
以上示例將輸出:
class DeepThought#1 (1) {
public ${0} =>
int(42)
}