title: PHP force instance of Closure, sort of
body: <p>To quote PHP:</p>
  
  <blockquote>
    <p>Anonymous functions are currently implemented using the <strong><a href="http://ca3.php.net/manual/en/reserved.classes.php#reserved.classes.closure" rel="nofollow">Closure</a></strong> class. This is an implementation detail and should not be relied upon.</p>
  </blockquote>
  
  <p>Now, that said, the following checks are deemed unreliable:</p>
  
  <pre><code>function myFunction(Closure $callback){}
  
  if(!($callback instanceof Closure)){}
  </code></pre>
  
  <p>Which brings us to using <code>is_callable()</code>. This is fine, however if one <em>requires</em> a true "<strong>closure</strong>", (<em>as an argument, or what-such</em>) then <code>is_callable()</code> isn't strict enough. The following of course dumps <code>bool(true)</code> for each:</p>
  
  <pre><code>function myFunction(){}
  
  class MyClass{
      public function __invoke(){}
  }
  
  var_dump(is_callable('myFunction'));
  var_dump(is_callable(new MyClass));
  </code></pre>
  
  <p>How, without relying on the <code>Closure</code> class (<em>given is <strong>is</strong> in fact unreliable</em>) can one strictly identify a "<strong>closure</strong>"?</p>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>It has occurred to me I was falling in the direction of bad design. However, despite this question being answered, I think it would be appreciated if anyone could suggest answers to the posed question, if not purely for the academic element of it.</p>
  
  <h2>Update (<em>again</em>)</h2>
  
  <p>Since the release of PHP 5.4 (<em>awhile ago now</em>) the <code>Closure</code> type is no longer an "implementation detail", and can be relied on. <code>function f(Closure $g) { }</code> is all good.</p>