メソッドがオブジェクトの外側から呼び出されたのか、内側から呼び出されたのかを判断するにはどうすればよいですか?
例えば:
class Example{
public function Foo(){
$this->Bar();
}
public function Bar(){
if(this_function_was_called_from_outside_the_object){
echo 'I see you\'re an outsider!' // this method was invoked from outside the object.
}else{
echo 'I\'m talking to myself again.'; // this method was invoked from another method in this object.
}
}
}
$oExample = new Example();
$oExample->Foo(); // I\'m talking to myself again.
$oExample->Bar(); // I see you\'re an outsider!