note 102739 added to language.oop5.basic

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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 ) );
	}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 65.46.73.46
----
Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php
Edit        -- https://master.php.net/note/edit/102739
Del: integrated  -- https://master.php.net/note/delete/102739/integrated
Del: useless     -- https://master.php.net/note/delete/102739/useless
Del: bad code    -- https://master.php.net/note/delete/102739/bad+code
Del: spam        -- https://master.php.net/note/delete/102739/spam
Del: non-english -- https://master.php.net/note/delete/102739/non-english
Del: in docs     -- https://master.php.net/note/delete/102739/in+docs
Del: other reasons-- https://master.php.net/note/delete/102739
Reject      -- https://master.php.net/note/reject/102739
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.