3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { /** @var array<string, string> */ private array $stuff = ["foo" => "foo"]; /** * @param non-empty-list<string> $param * @return string */ public function foo(array $param) { $arr = &$this->stuff[$param[0]]; // This seems to cause Psalm to blackout. var_dump($this->stuff); /** @var string */ $x = $arr; /** @psalm-trace $x, $arr */; // This trace doesn't work, and $x's type appears to be mixed at this point. /** @psalm-trace $x */ return $x; } } $foo = new Foo(); $foo->foo(["foo"]); $foo->foo(["bar"]);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array(1) { ["foo"]=> &string(3) "foo" } array(2) { ["foo"]=> string(3) "foo" ["bar"]=> &NULL }
Output for 7.4.0 - 7.4.33
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Foo has a deprecated constructor in /in/f63nj on line 3 Fatal error: Uncaught ArgumentCountError: Too few arguments to function Foo::foo(), 0 passed in /in/f63nj on line 26 and exactly 1 expected in /in/f63nj:12 Stack trace: #0 /in/f63nj(26): Foo->foo() #1 {main} thrown in /in/f63nj on line 12
Process exited with code 255.

preferences:
83.72 ms | 402 KiB | 123 Q