Guest User

Untitled

a guest
Aug 20th, 2019
82
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Calculator
  2. {
  3. private $history = [];
  4.  
  5. public function add(int $a, int $b): int
  6. {
  7. $result = $a + $b;
  8.  
  9. $this->history[] = $result;
  10.  
  11. return $result;
  12. }
  13.  
  14. public function subtract(int $a, int $b): int
  15. {
  16. $result = $a - $b;
  17.  
  18. $this->history[] = $result;
  19.  
  20. return $result;
  21. }
  22.  
  23. public function history(): array
  24. {
  25. return $this->history;
  26. }
  27. }
  28.  
  29. function add(int $a, int $b): int
  30. {
  31. $calculator = new Calculator;
  32. return $calculator->add($a, $b);
  33. }
  34.  
  35. function subtract(int $a, int $b): int
  36. {
  37. $calculator = new Calculator;
  38. return $calculator->subtract($a, $b);
  39. }
  40.  
  41. function history(): array
  42. {
  43. $calculator = new Calculator;
  44. return $calculator->history(); // Clearly this will be empty
  45. }
  46.  
  47. function add(Calculator $calculator, int $a, int $b): int
  48. {
  49. return $calculator->add($a, $b);
  50. }
  51.  
  52. function history(Calculator $calculator): array
  53. {
  54. return $calculator->history();
  55. }
  56.  
  57. $GLOBALS['calculator'] = new $calculator;
  58.  
  59. function add(int $a, int $b): int
  60. {
  61. return $GLOBALS['calculator']->add($a, $b);
  62. }
  63.  
  64. function history(): array
  65. {
  66. return $GLOBALS['calculator']->history();
  67. }
RAW Paste Data