Values & References8 / 16
Up next

Objects are mutable in callees

<?php
declare(strict_types=1);
class Counter {
    public int $n = 0;
}
// the handle is copied, but it points at the same object
function tick(Counter $c): void {
    $c->n++;
}
$c = new Counter();
tick($c);
tick($c);
echo $c->n, "\n";
What you're solving

no & needed to mutate an object