I've got some PHP cruft that I would like to delegate methods. Sort of a poor-man's mixin.
Basically I would like the following:
<?php
class Apprentice
{
public function magic() {
echo 'Abracadabra!';
}
}
class Sourcerer // I work magic with the source
{
private $apprentice;
public function __construct(){
$this->apprentice = new Apprentice();
}
public function __get($key) {
if (method_exists($this->apprentice, $key)) {
return $this->apprentice->{$key};
}
throw Exception("no magic left");
}
}
$source = new Sourcerer();
$source->magic();
?>
To not throw a Fatal error: Call to undefined method Sourcerer::magic() in .../test__get.php
.