title: Correct way to inject and use a named function in a class / object?
body: <p>What's the common practice when one needs to inject a normal, named function in a class / object? I can inject an anonymous function / closure created with <code>function() {}</code> but most of the times I may prefer traditional static functions.</p>
  
  <p>For instance, I want to inject a named function as <code>Some::func()</code> in the class <code>Test</code>. Do I just pass in the name of the function as a string? Or is there any other better way?</p>
  
  <p>This is what I come up with thus far:</p>
  
  <pre><code>class Test {
      private $func;
      public function __construct($func) {
          $this -&gt; func = array(
              'name' =&gt; $func
          );
      }
      public function run() {
          $this -&gt; func['name']();
      }
      public function run2() {
          Some::func();
      }
      public function run3() {
          call_user_func_array($this -&gt; func['name'], array());
      }
  }
  
  class Some {
      static function func() {
          echo 'Success!';
      }
  }
  
  $test = new Test('Some::func');
  $test -&gt; run(); // Call to undefined function Some::func()
  $test -&gt; run2(); // Works!
  $test -&gt; run3(); // Works!
  </code></pre>
  
  <p>The first <code>run()</code> looks much better albeit not working. And the error sounds weird to me because <code>Some::func()</code> is definitely defined in there as the other ways work properly.</p>
  
  <p>Seems to me <code>call_user_func_array()</code> is the only way here? Is there any way I can make the first approach <code>run()</code> work? If not, why? </p>