028.phpt 793 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. Test result of match cannot be modified by reference
  3. --FILE--
  4. <?php
  5. // opcache can't be certain Test::usesRef is actually this method
  6. if (!class_exists('Test')) {
  7. class Test {
  8. public static function usesRef(&$x) {
  9. $x = 'modified';
  10. }
  11. public static function usesValue($x) {
  12. echo "usesValue $x\n";
  13. }
  14. }
  15. }
  16. function main(int $i): int {
  17. Test::usesValue(match(true) { true => $i });
  18. Test::usesValue(match($i) { 42 => $i });
  19. var_dump($i);
  20. Test::usesRef(match(true) { true => $i });
  21. var_dump($i);
  22. }
  23. try {
  24. main(42);
  25. } catch (Error $e) {
  26. printf("Caught %s\n", $e->getMessage());
  27. }
  28. ?>
  29. --EXPECT--
  30. usesValue 42
  31. usesValue 42
  32. int(42)
  33. Caught Test::usesRef(): Argument #1 ($x) cannot be passed by reference