Hacker News new | ask | show | jobs
by CiaranMcNulty 2021 days ago
>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')

1 comments

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.