note 102142 added to language.oop5.inheritance
| From: | msg2maciej at aol dot com | Date: | Sat, 29 Jan 2011 00:08:45 +0000 |
| Subject: | note 102142 added to language.oop5.inheritance | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176487@lists.php.net to get a copy of this message | ||
PHP supports single class inheritance. My bare idea on accessing protected methods with power of
abstracts and sort of "multi-class inheritance SIMULATION":
<?php
error_reporting(E_ALL);
abstract class Base {
abstract protected function __construct ();
abstract protected function hello_left ();
abstract protected function hello_right ();
}
abstract class NotImplemented_Left extends Base {
protected function hello_right () {
echo 'well, wont see that'; }}
abstract class NotImplemented_Right extends Base {
protected function hello_left () {
echo 'well, wont see that'; }}
class Left extends NotImplemented_Left {
protected function __construct () { # limited visibility, no access from "outside"
echo __CLASS__.'::protected __construct'. "\n"; }
protected function hello_left () { # limited visibility, no access from "outside"
echo 'protected hello_left in ' . __CLASS__ . "\n"; }}
class Right extends NotImplemented_Right {
protected function __construct () { # limited visibility, no access from "outside"
echo __CLASS__.'::protected __construct'. "\n"; }
protected function hello_right () { # limited visibility, no access from "outside"
echo 'protected hello_right in ' . __CLASS__ . "\n"; }
protected function hello_left () {
echo "wont see that, and easy to get rid of it from here\n"; }}
class Center extends Base {
private $left;
private $right;
public function __construct () {
echo 'welcome in ' . __CLASS__ . "\n";
echo 'Center::'; $this->left = new Left;
echo 'Center::'; $this->right = new Right;
echo " oh and\n";
$this->hello_left();
$this->hello_right();
}
public function hello_left () { # calling class Left
echo __CLASS__.'::'; $this->left->hello_left(); }
public function hello_right () { # calling class Right
echo __CLASS__.'::'; $this->right->hello_right(); }
}
$c = new Center;
?>
Produces:
welcome in Center
Center::Left::protected __construct
Center::Right::protected __construct
oh and
Center::protected hello_left in Left
Center::protected hello_right in Right
----
Server IP: 69.147.83.197
Probable Submitter: 76.100.12.47
----
Manual Page -- http://www.php.net/manual/en/language.oop5.inheritance.php
Edit -- https://master.php.net/note/edit/102142
Del: integrated -- https://master.php.net/note/delete/102142/integrated
Del: useless -- https://master.php.net/note/delete/102142/useless
Del: bad code -- https://master.php.net/note/delete/102142/bad+code
Del: spam -- https://master.php.net/note/delete/102142/spam
Del: non-english -- https://master.php.net/note/delete/102142/non-english
Del: in docs -- https://master.php.net/note/delete/102142/in+docs
Del: other reasons-- https://master.php.net/note/delete/102142
Reject -- https://master.php.net/note/reject/102142
Search -- https://master.php.net/manage/user-notes.php