Can’t read a const in a class instance?

Because constants just aren’t instance members; they’re statically bound to their respective types. In the same way you can’t invoke static methods using instances, you can’t access class constants using instances.

If you need to get a constant off an instance without knowing its type first-hand, I suppose you could do it with reflection based on its type.

If you’re trying to add a member that can’t be modified but pertains to instances, you probably want read-only fields or properties instead.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)