Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Calculator
- {
- private $history = [];
- public function add(int $a, int $b): int
- {
- $result = $a + $b;
- $this->history[] = $result;
- return $result;
- }
- public function subtract(int $a, int $b): int
- {
- $result = $a - $b;
- $this->history[] = $result;
- return $result;
- }
- public function history(): array
- {
- return $this->history;
- }
- }
- function add(int $a, int $b): int
- {
- $calculator = new Calculator;
- return $calculator->add($a, $b);
- }
- function subtract(int $a, int $b): int
- {
- $calculator = new Calculator;
- return $calculator->subtract($a, $b);
- }
- function history(): array
- {
- $calculator = new Calculator;
- return $calculator->history(); // Clearly this will be empty
- }
- function add(Calculator $calculator, int $a, int $b): int
- {
- return $calculator->add($a, $b);
- }
- function history(Calculator $calculator): array
- {
- return $calculator->history();
- }
- $GLOBALS['calculator'] = new $calculator;
- function add(int $a, int $b): int
- {
- return $GLOBALS['calculator']->add($a, $b);
- }
- function history(): array
- {
- return $GLOBALS['calculator']->history();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement