Re: inheritance check too strict?
| From: | Stas Malyshev | Date: | Thu, 19 Aug 2010 08:13:07 +0000 |
| Subject: | Re: inheritance check too strict? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49449@lists.php.net to get a copy of this message | ||
Hi!
I was under the impression that, in order for inheritance to provide proper polymorphism, overridden methods should share the parent's method signature, although they can have additional optional arguments.Your impression is wrong. Overriden method should have _compatible_ signature - i.e. accept any argument set that parent object accepted. Nothing requires it to have the same signature.
Otherwise, if you're passed an ObjChild when you are treating it as an ObjParent, you could get unexpected behaviour if it ignores $param2 when you decide to specify it. PHP doesn't complain about a programmerUnexpected by whom? Writer of ObjChild->set() knew how to implement it without that parameter, so why behavior would be unexpected?
passing too many arguments to the function as far as I recall, so this sort of bug can be easy to overlook.How this is a "bug"? -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227