| 3454 | class DeepVariableChainDemo |
| 3455 | { |
| 3456 | public function demo(): void |
| 3457 | { |
| 3458 | // 5-level chain: each variable is assigned from a method/property on the previous. |
| 3459 | $brush = new Brush(); |
| 3460 | $canvas = $brush->getCanvas(); |
| 3461 | $easel = $canvas->easel; |
| 3462 | $material = $easel->material; // string from Easel::$material |
| 3463 | $back = $canvas->getBrush(); |
| 3464 | $back->stroke(); // Brush::stroke() — full round-trip |
| 3465 | |
| 3466 | // Reassignment chains: the resolver picks the most recent assignment. |
| 3467 | $tool = new Pen(); |
| 3468 | $tool->write(); // Pen::write() |
| 3469 | $tool = new Pencil(); |
| 3470 | $tool->sketch(); // Pencil::sketch() — Pen::write() is gone |
| 3471 | $tool = new Marker(); |
| 3472 | $tool->highlight(); // Marker::highlight() |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | |