Hacker News new | past | comments | ask | show | jobs | submit login

> Inside a method on a Case, The $this variable is defined and refers to the Case instance.

Say what? Where does this instance come from and what is its scope?

> By default, Enumerated Cases have no primitive equivalent. They are simply singleton objects.

So, singletons. That way you end up with more global state, with all its consequences.

> the following features of objects are not allowed on enumerations:

> Enum/Case properties

Ok, so these are objects without properties. That could solve the global state problem but at this point you may just as well skip the entire object part as I don't see why exactly it's needed for an identity check.

Also, enumerations may have static methods but the provided example says "public function" without the static modifier.




>So, singletons. That way you end up with more global state, with all its consequences.

As you point out, the lack of properties solves that. The use of a singleton probably relates to the identity issue

> at this point you may just as well skip the entire object part as I don't see why exactly it's needed for an identity check.

PHP only has 8 types (string, int, bool, float, array, null, resource, object) and they're not likely to be added to (resource is largely deprecated).

Given that, object is the only one that's not likely to be abused by relying on the actual scalar value. Keeping it as a singleton ensures that === will still work (it requires 'same instance')


Thanks for clearing that up.

There's one more thing not addressed by the RFC: how to check for a particular enum to exist. The way I see it, a new function "enum_exists" would be needed and validating a QCN would become this ugly:

class_exists($qcn) || enum_exists($qcn) || interface_exists($qcn) || trait_exists($qcn)


its implicitly addressed by saying enums map to objects and clarifying how "::class" works, i.e. enum_exists is not necessary, because its implementation would essentially be class_exists.


Ah, right. The assumption that "new ReflectionClass($qcn)" where "assert(class_exists($qcn))" works should still be valid as RefelctionEnum[sic] extends ReflectionClass.

I'm not completely certain on this, though. If not, it'd definitely break things.


its definitely a weak point of the RFC at the moment.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: