[nycphp-talk] Multi-Inheritance in PHP 5
Tim Gales
tgales at tgaconnect.com
Sun Oct 10 17:26:34 EDT 2004
Chris Snyder writes:
> That said, here's a demo of how to accomplish a limited
> multiple inheritance using the ClassKit extension:
>
> <?php
> class lucy {
> public $isLucy = TRUE;
> }
>
> class charlie extends lucy {
> public $isCharlie = "Good grief!";
> }
>
> class football {
> function kickBall() {
> if ( isset( $this->isLucy ) ) print "You missed!";
> else print "Good kick!";
> }
> }
>
> // give charlie the football
> classkit_method_copy ( "charlie", "kickBall", "football" );
>
> // charlie now extends lucy AND football
>
> $chuck = new charlie;
> print $chuck->kickBall();
> ?>
>
> Verified using PHP 5.0.1 on OSX.
What output did you get?
This looks to me like you have dynamically
implemented an interface -- and so have
gained only what interfaces give you.
Something which could have been written like:
interface IkickBall
{
public function kickBall();
}
class charlie extends lucy
implements IkickBall {
public $isCharlie = "Good grief!";
function kickBall() {
if ( isset( $this->isLucy ) ) print "You missed!";
else print "Good kick!";
}
}
(I could very easily be missing the point here)
T. Gales & Associates
'Helping People Connect with Technology'
http://www.tgaconnect.com
More information about the talk
mailing list