this.phpt 971 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. --TEST--
  2. ZE2 $this cannot be exchanged
  3. --FILE--
  4. <?php
  5. /* please don't shorten this test. It shows what would happen if
  6. * the fatal error would have been a warning.
  7. */
  8. class Foo
  9. {
  10. function replace($other)
  11. {
  12. echo __METHOD__ . "\n";
  13. $this = $other;
  14. print $this->prop;
  15. print $other->prop;
  16. }
  17. function indirect($other)
  18. {
  19. echo __METHOD__ . "\n";
  20. $this = $other;
  21. $result = $this = $other;
  22. print $result->prop;
  23. print $this->prop;
  24. }
  25. function retrieve(&$other)
  26. {
  27. echo __METHOD__ . "\n";
  28. $other = $this;
  29. }
  30. }
  31. $object = new Foo;
  32. $object->prop = "Hello\n";
  33. $other = new Foo;
  34. $other->prop = "World\n";
  35. $object->replace($other);
  36. $object->indirect($other);
  37. print $object->prop; // still shows 'Hello'
  38. $object->retrieve($other);
  39. print $other->prop; // shows 'Hello'
  40. ?>
  41. ===DONE===
  42. --EXPECTF--
  43. Fatal error: Cannot re-assign $this in %sthis.php on line %d