在函数的参数中,是否可以指定一些枚举值?
例如,代替这个:
public function getValuesFromType(string $type) { /*...*/ }
Run Code Online (Sandbox Code Playgroud)
我只想允许一些特定的值 - 像这样的伪代码:
public function getValuesFromType('a'||'b' $type) { /*...*/ }
Run Code Online (Sandbox Code Playgroud)
我尝试创建一个包含值的枚举对象,并在类型中添加枚举。但是当该函数getValuesFromType('a')运行时,会出现错误argument 1 must be of type MyTypeEnum, string given...
public function getValuesFromType(MyTypeEnum $type)
Run Code Online (Sandbox Code Playgroud)
如何限制可以作为参数传递给此方法的值?