title: PHP - Can you assign a member function to a variable?
body: <p>In PHP5, variables can be evaluated as functions<a href="http://php.net/manual/en/functions.variable-functions.php" rel="noreferrer">1</a> such as:</p>
  
  <pre><code>function myFunc() {
     echo "whatever";
  }
  
  $callableFunction = 'myFunc';
  
  $callableFunction(); // executes myFunc()
  </code></pre>
  
  <p>Is there any syntax for assigning object member functions to a variable such as:</p>
  
  <pre><code>class MyClass {
      function someCall() {
          echo "yay";
      }
  }
  
  $class = new MyClass();
  
  // what I would like:
  $assignedFunction = $class-&gt;someCall; // but I tried and it returns an error
  
  $memberFunc = 'someCall';
  $class-&gt;$memberFunc(); // I know this is valid, but I want a single variable to be able to be used to call different functions - I don't want to have to know whether it is part of a class or not.
  
  // my current implementation because I don't know how to do it with anonymous functions:
  $assignedFunction = function() { return $class-&gt;someCall(); } // &lt;- seems lengthy; would be more efficient if I can just assign $class-&gt;someCall to the variable somehow?
  
  $assignedFunction(); // I would like this to execute $class-&gt;someCall()
  </code></pre>