In using PHP’s DOM classes (DOMNode, DOMEElement, etc) I have noticed that they possess truly readonly properties. For example, I can read the $nodeName property of a DOMNode, but I cannot write to it (if I do PHP throws a fatal error).
How can I create readonly properties of my own in PHP?
You can do it like this:
Only use this when you really need it – it is slower than normal property access. For PHP, it’s best to adopt a policy of only using setter methods to change a property from the outside.