SmartObject.referenceProperty.phpt 486 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Test: Nette\SmartObject reference to property.
  4. */
  5. declare(strict_types=1);
  6. use Tester\Assert;
  7. require __DIR__ . '/../bootstrap.php';
  8. /**
  9. * @property string $foo
  10. */
  11. class TestClass
  12. {
  13. use Nette\SmartObject;
  14. private $foo;
  15. public function getFoo()
  16. {
  17. return $this->foo;
  18. }
  19. public function setFoo($foo)
  20. {
  21. $this->foo = $foo;
  22. }
  23. }
  24. $obj = new TestClass;
  25. $obj->foo = 'hello';
  26. @$x = &$obj->foo;
  27. $x = 'changed by reference';
  28. Assert::same('hello', $obj->foo);