PHP Chainnable Static Method

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

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.