MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / demo

Method demo

examples/demo.php:753–773  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

751class ForeachByReferenceDemo
752{
753 public function demo(): void
754 {
755 /** @var list<Pen> $pens */
756 $pens = getUnknownValue();
757
758 // By-reference foreach: $pen resolves to element type (Pen)
759 // and is not flagged as undefined or unused.
760 foreach ($pens as &$pen) {
761 $pen->write(); // Pen from list<Pen>
762 $pen = new Pen(); // reassignment through reference
763 }
764 unset($pen);
765
766 // Key-value with by-reference value
767 /** @var array<string, Pen> $named */
768 $named = getUnknownValue();
769 foreach ($named as $key => &$tool) {
770 $tool->color(); // Pen from array<string, Pen>
771 }
772 unset($tool);
773 }
774}
775
776

Callers

nothing calls this directly

Calls 3

getUnknownValueFunction · 0.85
writeMethod · 0.80
colorMethod · 0.80

Tested by

no test coverage detected