this.phpt 1.0 KB

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