note 58431 deleted from language.oop5.overloading by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 14:54:28 +0000 |
| Subject: | note 58431 deleted from language.oop5.overloading by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197221@lists.php.net to get a copy of this message | ||
Note Submitter: TJ <php at tjworld dot net>
----
Using the getter/setter methods to provide read-only access to object properties breaks the
conventional understanding of inheritence.
A super class using __set() to make a property read-only cannot be properly inherited because the
visible (read-only) property - with conventional public or protected visibility - cannot be set in
the sub-class.
The sub-class cannot overload the super class's __set() method either, and therefore the
inheritence is severely compromised.
I discovered this issue while extending DOMDocument and particularly DOMElement.
When extDOMDocument->createElement() creates a new extDOMElement, extDOMElement->__construct()
can't set the extDOMElement->ownerDocument property because it's read-only.
DOMElements are totally read-only if they do not have an ownerDocument, and there's no way to
set it in this scenario, which makes inheritence pretty pointless.