The code snippet below shows an interesting technique to daisy chain calls to a particular method without having to implicitly call the parent::method() in the child method. It takes advantage of php's __call and self

<?php

class b extends a
{
	public function _init()
	{
		echo 'hello from b::_init<br>';
	}
}

class a
{
	public function _init()
	{
		echo 'hello from a::_init<br';
	}

	public function __call($n, $a)
	{
		echo 'hello from a::__call<br>';
		call_user_func_array(array($this, '_'.$n), $a);
		call_user_func_array(array(self, '_'.$n), $a);
	}
}

$obj = new b;
$obj->init();

?>

Related posts:

  1. PHP Named Parameters
  2. PHP Simple Profiling Class
  3. PHP Parallel Web Scraper
  4. PHP fast, large (megabyte), data transfer between sessions
  5. PHP Array to String