Вы, вероятно, ищете __call()
.Он будет вызываться всякий раз, когда вызывается недоступный метод.
class MyClass {
protected function doStuff() {
echo "doing stuff.";
}
public function __call($methodName, $params) {
echo "In before method.";
return $this->doStuff();
}
}
$class = new MyClass();
$class->doStuff(); // In before method.doing stuff.