title: Accessing private/protected properties of an object in anonymous function in PHP
body: <p>I'm trying to dump elements of an object's private property through an anonymous function - of course I could achieve this in any number of other ways, but this highlights a PHP conundrum I can't solve off the top of my head, short of $foo = $this and using $foo - but THAT won't give me the private stuff, so... suggestions ?</p>
  
  <p>Sample code:</p>
  
  <pre><code>class MyClass
  {
      private $payload = Array( 'a' =&gt; 'A element', 'b' =&gt; 'B element');
  
      static $csvOrder = Array('b','a');
  
      public function toCSV(){
          $values = array_map(
              function($name) use ($this) { return $this-&gt;payload[$name]; },  
              self::$csvOrder
          );
          return implode(',',$values);
      }
  }
  
  $mc = new MyClass();
  print $mc-&gt;toCSV();
  </code></pre>