PHP Chainnable Static Method #2

<?php /** * ----------------------------------------------- * echo Foo::start(3)->plus(2)->minus(.4); * ----------------------------------------------- */ class Foo { public $init = 0; public function __construct($num) { $this->init = $num; } public function plus($num) { $this->init += $num; return $this; } public function minus($num) { $this->init -= $num; return $this; } public function is() { return $this->init; } public static function start($num) { return new static($num); } public function __toString() { return $this->is(); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.