027.phpt 773 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() {
  17. $i = 0;
  18. Test::usesValue(match(true) { true => $i });
  19. echo "i is $i\n";
  20. $j = 1;
  21. Test::usesRef(match(true) { true => $j });
  22. echo "j is $j\n";
  23. }
  24. main();
  25. ?>
  26. --EXPECTF--
  27. usesValue 0
  28. i is 0
  29. Fatal error: Uncaught Error: Test::usesRef(): Argument #1 ($x) cannot be passed by reference in %s:%d
  30. Stack trace:
  31. #0 %s(%d): main()
  32. #1 {main}
  33. thrown in %s on line %d