.
class First {
public function a() {
$second = new Second();
$second->b($this);
}
}
class Second {
public function b($context) {
if (!$context instanceof First)
throw new Exception('Can only be called from context of "First".');
echo 'b';
}
}
class Third {
public function c() {
$second = new Second();
$second->b($this);
}
}
Warning This does not prevent the Thirdmethod from being called , as it may provide a reference to the instance Second. But this makes the process more rigorous, and your documentation may indicate why it works this way.
Perhaps this will be useful, it seems to apply to a similar problem, which I had was not bad.
source
share