Since PHP 8.1 the native support for readonly properties arrived. But we already have constants with visibilities.
Please help me to answer these two questions:
Difference in write
One big difference is that you can't set class constants dynamically at runtime, which you can do with readonly properties (from the constructor).
Difference in read
There's also a big difference in how you access the two. Unless the property is static, you will need to have an instance (and all instances can have different values), while constants can always be access without an instance.
Props to M. Eriksson
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With