3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Name implements \Stringable { public function __construct(public readonly string $name) { } public function __toString(): string { return $this->name; } } enum Value: string { case id = 'id'; } function create(\WeakMap $map): \WeakMap { $name = new Name('func'); if (!isset($map[$name])) { $map[$name] = 'func-val'; } echo "In function scope:\n\n"; var_dump($map); echo PHP_EOL; return $map; } $name = new Name('global'); $map = new \WeakMap(); $map[$name] = 'global-val'; $map = create($map); echo "\n"; echo "In global scope:\n\n"; // watch the `Name('func')` key not being present here var_dump($map);

preferences:
31.07 ms | 404 KiB | 5 Q