title: Using $this when not in object context error within array_walk
body: <p>I am experiencing an odd problem with using <code>array_walk</code> with closures within a class. The problem does not arise within my development environment using php version <strong>5.4.7</strong> but it does on my deployment environment <strong>5.3.3</strong>.</p>
  
  <p>The following code runs fine on my production box, but crashes on my deployment environment:</p>
  
  <pre><code>&lt;?php
      error_reporting(-1);
  
      Class TestArrayWalk
      {
          /** @var null|array */
          protected $userInput = null;
  
          /**
           * This expects to be passed an array of the users input from
           * the input fields.
           *
           * @param  array $input
           * @return void
           */
          public function setUserInput( array $input )
          {
              $this-&gt;userInput = $input;
  
              // Lets explode the users input and format it in a way that this class
              // will use for marking
              array_walk( $this-&gt;userInput, function( &amp;$rawValue )
                  {
                      $rawValue = array(
                          'raw' =&gt; $rawValue,
                          'words' =&gt; $this-&gt;splitIntoKeywordArray( $rawValue ),
                          'marked' =&gt; false,
                          'matched' =&gt; array()
                      );
                  }
              );
          }
  
          public function getUserInput()
          {
              return $this-&gt;userInput;
          }
  
          protected function splitIntoKeywordArray( $input )
          {
              if ( ! is_string( $input )){ return array(); }
              return preg_split('/(\s|[\.,\/:;!?])/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
          }
  
      }
  
  
      $testArrayWalk = new TestArrayWalk();
      $testArrayWalk-&gt;setUserInput(
              array(
                  'This is a test input',
                  'This is another test input'
                  )
          );
  
      var_dump( $testArrayWalk-&gt;getUserInput() );
  </code></pre>
  
  <p>The error I am getting is: <code>Using $this when not in object context on line 26</code> which is the only usage of <code>$this</code> within that test class. I am assuming something changed between the versions I am using that has made the above code possible in my development environment.</p>
  
  <p>I also assume that as I cant change the deployment environment (its the clients and they wont change it) that I am going to have to use a <code>foreach</code> rather than <code>array_walk</code>.</p>
  
  <p><strong>My question is this:</strong> Given the above, is this possible in 5.3.3 using <code>array_walk</code> if not how do I use <code>foreach</code> in the same way that I am using array_walk ( more specifically the <code>&amp;$rawValue</code> bit)?</p>
  
  <p>My environments are:</p>
  
  <ul>
  <li>My development environment is PHP version <strong>5.4.7</strong></li>
  <li>My server (deployment) environment is PHP version <strong>5.3.3</strong></li>
  </ul>
  
  <p>Thanks.</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>Thanks to everyone who helped. With your help I got this working and have posted my working code to <a href="https://gist.github.com/carbontwelve/6727555" rel="nofollow">https://gist.github.com/carbontwelve/6727555</a> for future reference.</p>