note 40790 deleted from ref.overload by sobak
| From: | sobak@php.net | Date: | Tue, 22 Nov 2016 03:49:22 +0000 |
| Subject: | note 40790 deleted from ref.overload by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207449@lists.php.net to get a copy of this message | ||
Note Submitter: Metal
----
Overload and Inheritance.
After wasting a few hours trying to get it to work, it seems appropriate to put a warning here.
Short Version:
DON'T ever subclass an overloaded class. EVER.
Corollary:
If an overloaded class simply must be subclassed, rewrite the parent class to get rid of the
overloading. It can be as simple as commenting out the overload() statement and calling the
get/set/call methods explicitely.
This was the road I ended up taking.
Long Version:
While it is, in theory, possible to end up with a working subclass, it requires much mucking and
OO-principles compromise.
There is a great post that details the problem at great length. For those with the stomach, the URL
is:
http://www.zend.com/lists/engine2/200201/msg00140.html
If you're still thinking about mixing inheritance and overloading, at least read the "Best
Practices for the overload functions" in the URL above. If that doesn't change your mind,
at least you'll be able to avoid most of the pitfalls.