title: PHP anonymous function declaration in an existing class object
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1633012/initialize-class-property-with-an-anonymous-function">Initialize class property with an anonymous function</a>  </p>
  </blockquote>
  
  
  
  <p>I've been programing PHP for quite a while, and PHP 5.3 anonymous functions are one of those thinks that help you out a lot while building some simple scripts. However, I cannot understand why would the following example won't work?</p>
  
  <pre><code>$db         = new PDO([..]);
  $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  $db-&gt;die    = function($str){ die(var_dump( $str )); };
  
  $db-&gt;die('[..]');
  </code></pre>
  
  <p>After all, all I do is declare anonymous function on ->die property of PDO instance. This kinda makes me think this is a PHP bug.</p>