note 59124 added to keyword.extends
| From: | alanhogan at osu1 dot php dot net | Date: | Sun, 27 Nov 2005 01:48:15 +0000 |
| Subject: | note 59124 added to keyword.extends | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99164@lists.php.net to get a copy of this message | ||
Just a note: It is possible to have a class inherit from multiple other classes, but only in a
one-at-a-time linear hierarchy.
So this works, and C gets A and B functions:
<?php
class A {
public function af() { print 'a';}
public function bark() {print ' arf!';}
}
class B extends A {
public function bf() { print 'b';}
}
class C extends B {
public function cf() { print 'c';}
public function bark() {print ' ahem...'; parent::bark();}
}
$c = new C;
$c->af(); $c->bf(); $c->cf();
print "<br />";
$c->bark();
/**results:**/
//abc
//ahem... arf!
?>
This does NOT work:
<?php
class A {
public function af() { print 'a';}
public function bark() {print ' arf!';}
}
class B {
public function bf() { print 'b';}
}
class C extends B, A /*illegal*/ {
public function cf() { print 'c';}
public function bark() {print ' ahem...'; parent::bark();}
}
$c = new C;
$c->af(); $c->bf(); $c->cf();
print "<br />";
$c->bark();
//Parse Error
?>
----
Manual Page -- http://www.php.net/manual/en/keyword.extends.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59124
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59124&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59124&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59124&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59124&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59124&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59124&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59124&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59124&report=yes
Search -- http://master.php.net/manage/user-notes.php