<?php
abstract class xGrandparent {
public function __construct( $params = array() ){
foreach( $params as $k => $v ){
if( property_exists($this, $k) ){
$this->$k = $v;
} else {
switch($k){
case 'e':
throw new Exception('exception e', 111);
break;
case 'f':
throw new Exception('exception f', 222);
break;
}
}
}
}
}
abstract class xParent extends xGrandparent {
protected
$c,
$d
;
public function __construct( $params = array() ){
try {
parent::__construct( $params );
} catch ( Exception $e ){
if( $e->getCode() == 222 ){
echo "*** parent caught exception \n";
} else {
throw $e;
}
}
}
}
class xChild extends xParent {
protected
$a,
$b
;
public function __construct( $params = array() ){
try {
parent::__construct( $params );
} catch ( Exception $e ){
echo "*** child caught exception \n";
}
}
}
$test = new xChild(array(
'a' => 'a val',
'c' => 'c val',
'e' => 'e val',
'f' => 'f val',
'b' => 'b val',
'd' => 'd val',
));
var_dump( $test );