Re: insteadof considered harmful
| From: | TR Shaw | Date: | Mon, 09 Apr 2012 13:58:00 +0000 |
| Subject: | Re: insteadof considered harmful | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-317492@lists.php.net to get a copy of this message | ||
On Apr 9, 2012, at 7:15 AM, Szczepan Hołyszewski wrote:
>
> I must admit with embarrassment that after months of googling and posting
> questions to various forums I still fail to understand the purpose of the
> "insteadof" keyword and the insteadof clause.
>
> As I currently see it, the whole insteadof clause is completely redundant. In
> a clause like this:
>
> Foo::tweak insteadof Bar;
>
> the "insteadof Bar" part does not specify any information that is not already
> unambiguously specified by the "Foo::tweak" part. "Foo::tweak;" already
> conveys the intention of using tweak from the trait Foo instead of any other
> trait that has a member named tweak. What if we are using seven such traits?
> Do we have to list them all after insteadof? Why do we have to explicitly
> enumerate things that we DON'T want to use?
>
> I would like to see a small code example where the insteadof clause provides
> information that is BOTH necessary to make the program unambiguous AND cannot
> be conveyed with the simple "Foo::tweak;" syntax. Absent such example, I
> consider "insteadof" harmful because it does nothing and adds a maintenance
> chore. It should be made optional and deprecated ASAP, and removed at some
> point in the future.
See http://us.php.net/manual/en/language.oop5.traits.php
and scroll down to conflict resolution
to see simple example. It is used to resolve method naming conflicts when multiple traits are used
to emulate multiple inheritance.
Tom