fork download
  1. <?php
  2.  
  3. class Example
  4. {
  5. public $properties;
  6.  
  7. public function functionA(int $number): string
  8. {
  9. if (is_null($this->properties)) {
  10. return 'bar';
  11. }
  12.  
  13. return $this->properties[$number]['from'] ?? 'bar';
  14. }
  15.  
  16. public function functionB(int $number): string
  17. {
  18. return $this->properties[$number]['from'] ?? 'bar';
  19. }
  20. }
  21.  
  22. $example = new Example();
  23.  
  24. /* Scenario with no value set */
  25. $a = $example->functionA(1);
  26. $b = $example->functionB(1);
  27.  
  28. var_dump($a, $b, $a === $b);
  29.  
  30. /* Scenario with value set */
  31. $example->properties = [
  32. 1 => [
  33. 'from' => 'Foo'
  34. ]
  35. ];
  36.  
  37. $a = $example->functionA(1);
  38. $b = $example->functionB(1);
  39.  
  40. var_dump($a, $b, $a === $b);
  41.  
  42.  
Success #stdin #stdout 0.02s 26048KB
stdin
Standard input is empty
stdout
string(3) "bar"
string(3) "bar"
bool(true)
string(3) "Foo"
string(3) "Foo"
bool(true)