如果方法的签名将 Map 集合作为参数的默认值,则在使用 ReflectionClass 检查该方法时会引发错误。
Cannot use collection initialization in non-collection class
该类看起来像:
<?hh //strict
namespace Acme;
class Foo
{
protected Map<string, string> $options;
public function __construct(Map<string, string> $options = Map{})
{
$this->options = $options;
}
}
并且反射错误发生在
$reflection = new ReflectionClass('Acme\Foo');
$reflection->getConstructor()->getParameters();
该类在实际使用时会正确实例化。我只能使用反射创建错误。
问题
是否有什么我做错了,或者我缺少什么概念,才能使这项工作按预期进行?我希望getProperties
返回该方法的属性,就像它对任何其他值/类型一样。