When I need to pass an enumeration in a php function, I do like :
public function my_function (MyEnum $second) {
switch ($second->get_value()) {
case MyEnum::foo:
....
}
....
}
class MyEnum {
const foo = 0;
const bar = 1;
private $value;
public function __construct ($value) {
$this->value = $value;
}
public function get_value () { return $this->value; }
}
and call like :
my_function(new MyEnum(MyEnum::foo));
Should I DO change my function as to write my_function(MyEnum::foo);
?
I keep writing this way because IDEs show types when auto-completing a function call and php is throwing an Exception if you use another type anyways. Also It is smoothing the documentation writing process.
So I thought this has a lot of advantages right ?
But maybe writing as the latter has others advantages or disadvantages I'm unaware of. Which could be them ?