1
$this->cache = Cache::factory(Cache::TYPE_VOLATILE);
2
3
$reflector = new ReflectionClass(get_class($this->cache));
4
5
foreach ($reflector->getMethod('get')->getParameters() as $param) {
6
var_dump((string) $param);
7
}它輸出如下: 1
string(32) "Parameter #0 [ <required> $key ]"
2
string(37) "Parameter #1 [ <optional> $cache_cb ]"
3
string(39) "Parameter #2 [ <optional> &$cas_token ]"幾秒後,調查輸出結果,我發現我沒有通過引用傳遞第三個參數($cas_token),但是在我確定我的版本之前,我仔細檢查了PHP文檔的Memcached::get(),事實發現$cas_token確實被引用傳遞過去了(通過&符號)。然後,我修改了我的擴展方法,第三個參數通過引用傳遞,一切又如預期的那樣。 當你需要確定一個API的時候,卻沒有相關的文檔,可以嘗試使用PHP的ReflectorClass來得到相關信息。