SmartObject.arrayProperty.phpt 471 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Test: Nette\SmartObject array property.
  4. */
  5. declare(strict_types=1);
  6. use Tester\Assert;
  7. require __DIR__ . '/../bootstrap.php';
  8. /**
  9. * @property array $items
  10. */
  11. class TestClass
  12. {
  13. use Nette\SmartObject;
  14. private array $items = [];
  15. public function &getItems()
  16. {
  17. return $this->items;
  18. }
  19. public function setItems(array $value)
  20. {
  21. $this->items = $value;
  22. }
  23. }
  24. $obj = new TestClass;
  25. $obj->items[] = 'test';
  26. Assert::same(['test'], $obj->items);