title: PHP array_walk() in class with multiple arguments
body: <p>Good day,</p>
  
  <p>I got the following issue.
  Have a method in a class that I want to call with <em>array_walk</em> with two arguments.</p>
  
  <pre><code>array_walk($fields, array($this, 'SetAlias'), $Table);
  </code></pre>
  
  <p>When I put a comment in the method <em>SetAlias()</em> it does respond. Hence it is being called.</p>
  
  <p><strong>The method being called is:</strong></p>
  
  <pre><code>private function SetAlias($value, $table){
      if(isset($this-&gt;alias[$table][$value]) === true){
              $value = $value.'` AS `'.$this-&gt;alias[$table][$value];
      }
      return($value);
  }
  </code></pre>
  
  <p><strong>Arguments</strong></p>
  
  <p>But when I print the function arguments it returns :</p>
  
  <pre><code>Array
      (
          [0] =&gt; parking_id
          [1] =&gt; 0
          [2] =&gt; parking
      )
  </code></pre>
  
  <p>Unfortunately this is not working for me.</p>
  
  <p>So I COULD change the method's arguments to:</p>
  
  <pre><code>private function SetAlias($value, $null, $table){
  </code></pre>
  
  <p>Still no results.</p>
  
  <p><strong>The code</strong>:</p>
  
  <pre><code>&lt;?php
  
  class Test {
      public  $fields                     =   array('parking' =&gt; array('parking_id', 'parking_country', 'parking_name'));
      public  $alias                          =   array();
  
  
  
      private function SetAlias($value, $table){
          if(isset($this-&gt;alias[$table][$value]) === true){
                  $value = $value.'` AS `'.$this-&gt;alias[$table][$value];
          }
          return($value);
      }
  
  
      public function GetFields($Table){
          $fields = $this-&gt;fields[$Table];
  
          if(isset($this-&gt;alias[$Table]) === true){
              array_walk($fields, array($this, 'SetAlias'), $Table);
          }
  
          return('`'.implode($fields, '`, `').'`');
      }
  
  }
  
  
  
  
  
  $example = new Test();
  $example-&gt;alias['parking'] = array('parking_id'=&gt;'id', 'parking_country'=&gt;'country');
  
  echo $example-&gt;GetFields('parking');
  ?&gt;
  </code></pre>
  
  <p>It currently returns:</p>
  
  <p><strong><code>parking_id</code>, <code>parking_country</code>, <code>parking_name</code></strong></p>
  
  <p>What am I missing?</p>
  
  <p><strong>Works <em>by VolkerK</em></strong></p>
  
  <pre><code>public function GetFields($table){
      $fields = $this-&gt;fields[$table];
  
      if(isset($this-&gt;alias[$table]) === true) {
          $fn = function($e) use ($table) {
              return $this-&gt;SetAlias($e, $table);
          };
          $fn = $fn-&gt;BindTo($this);
          $fields = array_map( $fn, $fields );
      }
  
      return('`'.implode($fields, '`, `').'`');
  }
  </code></pre>
  
  <blockquote>
    <p>Does not work in a static context though. Is it possible to make this
    work?</p>
  
  <pre><code>$fn = $fn-&gt;BindTo(__CLASS__);
  $SetFields = array_map( $fn, $SetFields );
  </code></pre>
    
    <ul>
    <li><em>Warning: Closure::bindTo() expects parameter 1 to be object, string    given</em></li>
    </ul>
  </blockquote>
  
  <p><strong>Static context</strong></p>
  
  <pre><code>&lt;?php
  
  class Test {
      public static $fields                           =   array('parking' =&gt; array('parking_id', 'parking_country', 'parking_name'));
      public static $alias                            =   array();
  
      private static function SetAlias($value, $table){
          if(isset(self::$alias[$table][$value]) === true){
              $value = $value.'` AS `'.self::$alias[$table][$value];
          }
          return($value);
      }
  
  
      public static function GetFields($table){
          $fields = self::$fields[$table];
  
          if(isset(self::$alias[$table]) === true) {
              $fn = function($e) use ($table) {
                  return self::SetAlias($e, $table);
              };
              $fn = $fn-&gt;BindTo(__CLASS__);
              $fields = array_map( $fn, $fields );
          }
  
          return('`'.implode($fields, '`, `').'`');
      }
  }
  
  
  
  
  
  Test::$alias['parking'] = array('parking_id'=&gt;'id', 'parking_country'=&gt;'country');
  
  echo Test::GetFields('parking');
  ?&gt;
  </code></pre>
  
  <blockquote>
    <p><strong>WORKS <em>VolkerK</em>:</strong></p>
  
  <pre><code> &lt;?php
  class Test {
      public static $fields   = array('parking' =&gt; array('parking_id', 'parking_country', 'parking_name'));
      public static $alias    = array();
  
      private static function SetAlias($value, $table){
          if(isset($table[$value]) === true){
              $value = $value.'` AS `'.$table[$value];
          }
          return($value);
      }
  
      protected static function getFieldMapper($table) {
          if( !isset(self::$alias[$table]) ) {
              return function($e) { return $e; };
          }
  
          $table = self::$alias[$table];
          return function($e) use ($table) {
              return Test::SetAlias($e, $table);
          };
      }
  
      public static function GetFields($table){
          $fields = array_map( self::getFieldMapper($table), self::$fields[$table]);
          return('`'.implode($fields, '`, `').'`');
      }
  }
  ?&gt;
  </code></pre>
  </blockquote>