title: Pass class method to a closure in PHP (similar to JS)
body: <p>In Javascript you can do this:</p>
  
  <pre><code>// Define a function
  function logIt(a, b) { console.log(a, b); }
  
  function somethingElse() {
      // Store it in a variable
      var theLog = logIt; 
      // Call it somewhere else *as the variable-name*
      asyncCall(function() { theLog(1, 2); });
  }
  </code></pre>
  
  <p>What I'd like to do in PHP is this:</p>
  
  <pre><code>class A
  {
      // Define a simple class method
      protected function echoIt($a, $b) {
          echo $a, $b;
      }
  
      public function doSomething(array $things) {
          $theEchoFunction = $this-&gt;echoIt; // save it for the next line
  
          // Get into a closure and pass the method as a variable
          array_map(function($thing) use ($theEchoFunction) { // &lt;-- this is the bit I'd like to do
              // Call the function directly from the variable
              $theEchoFunction($thing[0], $thing[1]);
          }, $things);
      }
  }
  </code></pre>
  
  <p>I know that it's easy enough to just do <code>$that = $this;</code> then pass <code>$that</code> through to the closure, but that means I can't access <code>$that-&gt;echoIt</code> because it's protected. Is it possible to send the method itself to the closure?</p>
  
  <p>This question could actually be the <a href="https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem">X/Y problem</a> I guess. What I want to do is call the protected method from inside the closure. I'd like to just pass the method so that the closure doesn't need to know that the class has an <code>echoIt</code> method.</p>