title: Chaining Static Methods in PHP?
body: <p>Is it possible to chain static methods together using a static class? Say I wanted to do something like this:</p>
  
  <pre><code>$value = TestClass::toValue(5)::add(3)::subtract(2)::add(8)::result();
  </code></pre>
  
  <p>. . . and obviously I would want $value to be assigned the number 14. Is this possible?</p>
  
  <p><strong>Update</strong>: It doesn't work (you can't return "self" - it's not an instance!), but this is where my thoughts have taken me:</p>
  
  <pre><code>class TestClass {
      public static $currentValue;
  
      public static function toValue($value) {
          self::$currentValue = $value;
      }
  
      public static function add($value) {
          self::$currentValue = self::$currentValue + $value;
          return self;
      }
  
      public static function subtract($value) {
          self::$currentValue = self::$currentValue - $value;
          return self;
      }
  
      public static function result() {
          return self::$value;
      }
  }
  </code></pre>
  
  <p>After working that out, I think it would just make more sense to simply work with a class instance rather than trying to chain static function calls (which doesn't look possible, unless the above example could be tweaked somehow).</p>