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);
Output for git.master_jit, git.master
In function scope: object(WeakMap)#2 (2) { [0]=> array(2) { ["key"]=> object(Name)#1 (1) { ["name"]=> string(6) "global" } ["value"]=> string(10) "global-val" } [1]=> array(2) { ["key"]=> object(Name)#3 (1) { ["name"]=> string(4) "func" } ["value"]=> string(8) "func-val" } } In global scope: object(WeakMap)#2 (1) { [0]=> array(2) { ["key"]=> object(Name)#1 (1) { ["name"]=> string(6) "global" } ["value"]=> string(10) "global-val" } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
24.2 ms | 406 KiB | 5 Q