note 102739 deleted from language.oop5.basic by danbrown
| From: | danbrown@php.net | Date: | Thu, 03 Mar 2011 02:51:12 +0000 |
| Subject: | note 102739 deleted from language.oop5.basic by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177517@lists.php.net to get a copy of this message | ||
Note Submitter: code dot zhili at gmail dot com
----
To hugo (@) apres (dot) net
Your code is really great, very useful.
This is a great example to extends the core functions of php OOP features.
<?php
class Multiple_inheritance {
public $bases = array();
static function error_die($errno, $errstr, $errfile, $errline) {
$backtrace = debug_backtrace();
$detail = $backtrace[4];
var_dump( $backtrace );
echo '<b>Fetal Error</b>: '.$errstr.' of class
<b>'.$detail['class'].'</b> in
<b>'.$detail['file'].'</b> on line
<b>'.$detail['line'].'</b><br/>';
die();
}
private function fatal( $text ) {
set_error_handler( array( 'inheritance', 'error_die' ) );
trigger_error( $text, E_USER_ERROR );
restore_error_handler();
}
function __call( $name, $args ) {
if( $this-> bases )
foreach( $this->bases as $base )
if( method_exists( $base, $name ) )
return $base->$name( $args );
$this->fatal( "Call to undefined method <b>".$name."</b>" );
}
function __set( $name, $value ) {
if( $this->bases ) {
foreach( $this->bases as $base ) {
if( property_exists( $base, $name )) {
$base->$name = $value;
return;
}
}
}
}
function __get( $name ) {
if( $this->bases ) {
foreach( $this->bases as $base ) {
if( property_exists( $base, $name ) ) {
return $base->$name;
}
}
}
}
function __isset( $name ) {
if( $this->bases ) {
foreach( $this->bases as $base ) {
if( property_exists( $base, $name ) ) {
return isset( $base->$name );
}
}
}
}
function __unset( $name ) {
if( $this->bases ) {
foreach( $this->bases as $base ) {
if( property_exists( $base, $name) ) {
unset( $base->$name );
}
}
}
}
function inherits( $name, $args = '' ) {
return array_unshift( $this->bases, new $name( $args ) );
}
}
?>