Closed iluuu1994 closed 3 years ago
So... You'd end up with this?
$r = new ReflectionEnumCase(Suit::Hearts);
$re = $r->getDeclaringClass();
$re instanceof ReflectionEnum; // true
$r2 = new ReflectionEnumCase(Suit::ConstThatReferencesHearts)->getDeclaringClass();
$r2 instanceof ReflectionEnum; // false
$r2 instanceof ReflectionClass; // true
I suppose that's Liskov safe, but still feels a little odd. The code seems less self-documenting to me.
$r2 would be still ReflectionEnum, as it's operating on the value. (and not the source of the const)
What @bwoebi said :slightly_smiling_face: If you tried new ReflectionEnumCase(Suit::class, 'ConstThatReferencesHearts')
then yes, that should fail.
Is there anything to do here? Ilija?
I just tried it and php was giving me some trouble. Let's forget about it ^^
I'm thinking about ways to make reflection simpler. This is one such thing. Instead of adding a redundant
ReflectionEnumCase::getEnum()
method we could simply overrideReflectionClassConst::getDeclaringClass()
and return aReflectionEnum
instance instead.