1
鑑於以下代碼結構是否有一種方法可以使用PHP 5.6獲取FooFactory-> createService方法的返回類型?我已經嘗試過ReflectionClass和ReflectionMethod類,但找不到方法。提前感謝。PHP:有沒有辦法獲得方法的返回類型?
class FooFactory implements FactoryInterface {
public function createService(/*args*/)
{
$foo = new Foo();
// ...
//inject dependencies
// ...
return $foo;
}
}
class Foo {
/*...methods...*/
}
編輯:我需要獲取類名而不創建FooFactory的實例。
不是在PHP 5中,你必須分析方法的實際代碼.... PHP7介紹迴歸typehinting,但它是隻有可選 –
http://php.net/manual/en/migration70.new-features.php –