Given that my class looks like this:
class Methods{
function a(){
return 'a';
}
function b(){
$this->a();
}
function c(){
$this->a();
}
}
Is it possible to ensure that function a can only be called from function b?
In the above example function c should fail. I could just include it in function b, but in the future I may want to let a() be called by some new functions (e.g. d() or e())
Start by learning the difference between public, private and protected methods… it’s useful to have at least a grasp of OOP basics before wanting to do something incredibly complicated like this.
Yes, it’s possible using debug_backtrace() to identify where the call to the method was made from; but it’s a very big overhead…. and I see no value in actually setting such a restriction.