<?php
class Mother
{
public function func2() { return 'Mother knows best'; }
}
class Father
{
private $_aClasses;
public function __construct()
{
$this->_aClasses = array( 'Mother' => new Mother);
}
public function func1() { return 'func1 from Father'; }
public function __call($sName, $aArguments)
{
foreach ($this->_aClasses as $oObj)
{
if (method_exists($oObj, $sName))
{
echo $oObj->$sName();
} else
{
var_dump($oObj);
} } } } $oF = new Father; $oF->func2(); ?>
This outputs "Mother knows best" even thought Father doesnt have a function func2().
No comments:
Post a Comment