3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Immutable { public function __construct(/** @psalm-readonly */ public stdClass $neverChange) {} public function mutate(): void { $this->neverChange->foo = 1; } } class DoOtherStuff { public function doStuff(Immutable $immutable): void { $immutable->mutate(); } } $data = new stdClass; $data->foo = 0; $immutable = new Immutable($data); /* ... */ if ($immutable->neverChange->foo === 0) { /* ... */ (new DoOtherStuff())->doStuff($immutable); /* Here I would assume, that my immutable object still holds the not change value stdClass::foo = 0 but it got mutated to stdClass::foo = 1 */ } echo "Does this code actually run without any syntax errors? " . ($immutable->neverChange->foo ? 'Me definetly think so...' : 'No, some internet rando was smarter than me rapid typing some example which everybody did understand anyways');
Output for 8.1.23 - 8.1.30, 8.2.7 - 8.2.24, 8.3.0 - 8.3.13
Does this code actually run without any syntax errors? Me definetly think so...

preferences:
38.21 ms | 406 KiB | 5 Q