Created
December 20, 2018 19:36
-
-
Save Dragomeat/015928082a8fdc16741ca285154b27c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
class Calculator | |
{ | |
private $result; | |
public function __construct(int $result = 0) | |
{ | |
$this->result = $result; | |
} | |
public function __invoke(int $number): self | |
{ | |
$this->result += $number; | |
return $this; | |
} | |
public function __toString(): string | |
{ | |
return (string) $this->result; | |
} | |
} | |
$calculator = new Calculator(); | |
echo $calculator; // 0 | |
echo $calculator(2)(3)(15); // 20 | |
echo $calculator(2)(5)(5); // 32 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment