0

This is a tricky one.

I am "emulating" ZF Bootstrapping (surface appearance). Don't ask me why, call it academic interest. So I have a Bootstrap Abstract with a method "run" that iterates over itself to locate any methods prefixed with "init".

The application looks for a user defined class which extends this class, in which the user can define any number of methods in this way. However, I want to prevent the user from being able to execute the "run" command of it's parent class, while still exposing the same command for the client code.

class Bootstrap_Abstract{
    protected final function run(){
    // if method exists that starts 'init' - execute the method
    }

}

class Bootstrap extends Bootstrap_Abstract(){
    public function initSomething(){
    //do something
    }

    //PREVENT THIS
    public function initRun(){
        $this->run();
    }

}

//application code, not exposed to user - changes in behaviour require changes in this code directly
 class Application(){
     $Bootstrap = new Bootstrap();//load user bootstrap
     $Bootstrap->run();
 }
sunwukung
  • 2,815
  • 3
  • 41
  • 56
  • Can you elaborate a bit on this sentence: "I want to prevent the user from being able to execute the "run" command of it's parent class, while still exposing the same command for the client code"? I don't quite understand. – thetaiko Apr 08 '10 at 15:24
  • Related: [PHP equivalent of friend or internal](http://stackoverflow.com/q/317835/212218) –  Jun 11 '12 at 21:18

2 Answers2

1

To determine "what" called a particular method, look into debug_backtrace

webbiedave
  • 48,414
  • 8
  • 88
  • 101
  • The OP illustrates an example of [the XY Problem](http://meta.stackexchange.com/q/66377/164291). Although this is technically the answer to the question, it isn't really the correct solution to the OP's problem. –  Jun 11 '12 at 21:16
0

Post Script: the problem with my original code was an error in design. The responsibility for iterating through the Bootstrap methods should have been given to the invoking class, not the target class itself. I solved this problem by moving the function out to the invoker. Funny how obvious/simple refactoring is in hindsight...

sunwukung
  • 2,815
  • 3
  • 41
  • 56