title: Is this implementation a fair example of a Promise in PHP?
body: <p>I've been reading about the Promise pattern, and I tried to code up a version in PHP with the help of a few examples and my own understanding of how it should work. Is what I came up with a reasonable example of the Promise pattern, or did I implement this incorrectly?</p>
  
  <pre><code>class PromiseClass {
      private $callbacks = array();
      private $last_return;
      function promise($promise) {
          if (get_class($promise) == 'Promise') {
              return $promise;
          } else if (is_callable($promise)) {
              $this-&gt;then($promise);
              return $this;
          }
      }
      public function then (callable $callback) {
          $this-&gt;callbacks[] = $callback;
          return $this;
      }
      public function resolve () {
          $callback = array_shift($this-&gt;callbacks);
          if (is_callable($callback)) {
              $this-&gt;last_return = $callback($this-&gt;last_return);
          }
          if (count($this-&gt;callbacks) &gt; 0) {
              $this-&gt;resolve();
          }
      }
  }
  </code></pre>
  
  <p>Example use:</p>
  
  <pre><code>$promiser-&gt;promise(function() {
          echo "sleeping\n";
          sleep(3);
          return 3;
      })
      -&gt;then(function($args) {
          echo " in second function, $args\n";
      });
  $promiser-&gt;resolve();
  </code></pre>