title: Passing method as parameter in PHP
body: <p>I have a class in PHP like this:</p>
  
  <pre><code>class RandomNumberStorer{
  
       var $integers = [];
  
       public function store_number($int){
           array_push($this-&gt;integers, $int);
       }
  
       public function run(){
           generate_number('store_number');
       }
  }
  </code></pre>
  
  <p>...elsewhere I have a function that takes a function as a parameter, say:</p>
  
  <pre><code>function generate_number($thingtoDo){ 
       $thingToDo(rand());
  }
  </code></pre>
  
  <p>So I initialise a <code>RandomNumberStorer</code> and run it:</p>
  
  <pre><code>$rns = new RandomNumberStorer();
  $rns-&gt;run();
  </code></pre>
  
  <p>And I get an error stating that there has been a 'Call to undefined function store_number'. Now, I understand that that with <code>store_number</code>'s being within the <code>RandomNumberStorer</code> class, it is a more a method but is there any way I can pass a class method into the <code>generate_number</code> function?</p>
  
  <p>I have tried moving the <code>store_number</code> function out of the class, but then I then, of course, I get an error relating to the reference to <code>$this</code> out of the context of a class/ instance. </p>
  
  <p>I would like to avoid passing the instance of <code>RandomNumberStorer</code> to the external <code>generate_number</code> function since I use this function elsewhere.</p>
  
  <p>Can this even be done? I was envisaging something like:</p>
  
  <pre><code> generate_number('$this-&gt;store_number')
  </code></pre>