PHP Conference Japan 2024

ReflectionClass::export

(PHP 5, PHP 7)

ReflectionClass::export匯出類別

警告

此函式已於 PHP 7.4.0 中_棄用_,並於 PHP 8.0.0 中_移除_。強烈建議不要依賴此函式。

說明

public static ReflectionClass::export(mixed $argument, bool $return = false): string

匯出一個反射類別。

參數

argument

要匯出的反射。

return

設定為 true 將會回傳匯出的結果,而不是輸出它。設定為 false(預設值)則會輸出結果。

回傳值

如果 return 參數設定為 true,則匯出結果會以 字串 型態返回,否則返回 null

範例

範例 #1 ReflectionClass::export() 的基本用法

<?php
class Apple {
public
$var1;
public
$var2 = 'Orange';

public function
type() {
return
'Apple';
}
}
ReflectionClass::export('Apple');
?>

上述範例將輸出類似以下的內容

Class [ <user> class Apple ] {
  @@ php shell code 1-8

  - Constants [0] {
  }

  - Static properties [0] {
  }

  - Static methods [0] {
  }

  - Properties [2] {
    Property [ <default> public $var1 ]
    Property [ <default> public $var2 ]
  }

  - Methods [1] {
    Method [ <user> public method type ] {
      @@ php shell code 5 - 7
    }
  }
}

另請參閱

新增註解

使用者貢獻的註解

此頁面沒有使用者貢獻的註解。
To Top