title: PHP 5.3 Magic Method __invoke
body: <p>This topic expands on <a href="https://stackoverflow.com/questions/250616/when-do-should-i-use-construct-get-set-and-call-in-php">When do/should I use __construct(), __get(), __set(), and __call() in PHP?</a>  which talks about the <code>__construct</code>, <code>__get</code> and <code>__set</code> magic methods.</p>
  
  <p>As of PHP 5.3 there is a new Magic Method called <code>__invoke</code>. The <code>__invoke</code> method is called when a script tries to call an object as a function.</p>
  
  <p>Now on research I have done for this method, people liken it to the Java method <code>.run()</code> - see <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runnable.html" rel="noreferrer">Interface Runnable</a>.</p>
  
  <p>Having thought long and hard about this I can't think of any reason why you would call <code>$obj();</code>  as opposed to <code>$obj-&gt;function();</code></p>
  
  <p>Even if you were iterating over an array of objects, you would still know the main function name that you would want to run.</p>
  
  <p>So is the <code>__invoke</code> magic method another example of 'just because you can, doesn't mean you should' shortcut in PHP, or are there cases where this would actually be the right thing to do?</p>