| 785 | public array $items = []; |
| 786 | |
| 787 | public function demo(): void |
| 788 | { |
| 789 | // Property typed as array<string, Pen> — variable key |
| 790 | $this->cache[$this->getKey()]->write(); // element type from generic annotation |
| 791 | |
| 792 | // Property typed as array<string, Pen> — string-literal key |
| 793 | $this->cache['brushes']->color(); // element type from generic annotation |
| 794 | |
| 795 | // Property typed as array<int, Pen> — numeric index |
| 796 | $this->items[0]->write(); // element type from generic annotation |
| 797 | |
| 798 | // Method chain after bracket access |
| 799 | $this->cache['tools']->rename('Fine')->write(); // chain through element type |
| 800 | } |
| 801 | |
| 802 | private function getKey(): string { return 'k'; } |
| 803 | } |