note 101937 added to keyword.extends
| From: | JamesM at osu1 dot php dot net | Date: | Wed, 19 Jan 2011 10:39:31 +0000 |
| Subject: | note 101937 added to keyword.extends | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175886@lists.php.net to get a copy of this message | ||
I have improved (f4bi0_ at hotmail dot com)'s answer to many extends. :)
<?php
class test {
private $_MODS;
public function __construct ( $mods ) {
$mods ? $this->_MODS = $mods : void;
}
public function __get( $var ) {
foreach ( $this->_MODS as $mod )
if ( property_exists( $mod, $var ) )
return $mod -> $var;
}
public function __call( $method, $args ) {
foreach ( $this->_MODS as $mod )
if ( method_exists( $mod, $method ) )
return call_user_method_array( $method, $mod, $args );
}
}
$mods = array();
class mod_test {
public function echoText ($text){
echo $text;
return true;
}
}
$mods[] = new mod_test();
$test = new test($mods);
var_dump($test);
echo $test -> getText();
?>
It works great, feel free to notify me with an even better way to do this (jamesm.sitegen/gmail
----
Server IP: 69.147.83.197
Probable Submitter: 220.233.38.77
----
Manual Page -- http://www.php.net/manual/en/keyword.extends.php
Edit -- https://master.php.net/note/edit/101937
Del: integrated -- https://master.php.net/note/delete/101937/integrated
Del: useless -- https://master.php.net/note/delete/101937/useless
Del: bad code -- https://master.php.net/note/delete/101937/bad+code
Del: spam -- https://master.php.net/note/delete/101937/spam
Del: non-english -- https://master.php.net/note/delete/101937/non-english
Del: in docs -- https://master.php.net/note/delete/101937/in+docs
Del: other reasons-- https://master.php.net/note/delete/101937
Reject -- https://master.php.net/note/reject/101937
Search -- https://master.php.net/manage/user-notes.php