On 20 Feb 2008, at 20:28, Lars Strojny wrote:

Am Mittwoch, den 20.02.2008, 20:14 +0000 schrieb Geoffrey Sneddon:
[...]
Is there any reason why we cannot support multiple inheritance (which
some other languages already do)? The only thing that needs to be
clearly defined is sorting order. This avoids trying to create some
entirely new functionality to do something where we can simply extend
what we already do.

Did you read the academic paper about the purpose of traits? In short:
traits fix the common misconceptions of multiple inheritance. The most
common problem is risky and fragile hierarchies. Also traits do the
right thing[tm]: they allow compositions, not uncontrolable hotchpotch
architectures.

Oh, wait. The previous email I was going to send in this thread was still a draft. That explains why that comment makes so little sense :)

What I was going to say is that how is something like:

<?php
trait foo {
        function output() {
                echo 'foo';
        }
}

trait bar {
        function output() {
                echo 'bar';
        }
}

class foobar {
        use foo;
        use bar;
}
?>

Better than:

<?php
class foo {
        function output() {
                echo 'foo';
        }
}

class bar {
        function output() {
                echo 'bar';
        }
}

class foobar extends foo, bar {
}
?>

Both are ambiguous if there is no documented conflict resolution: just because there's a proposal for traits doesn't mean you can't clearly define conflict resolution for multiple inheritance. I don't see either being intrinsically better than the other (and yes, I have read the papers about both).


--
Geoffrey Sneddon
<http://gsnedders.com/>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to