3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** @param array{foo: string} $strArr */ function bar(array $strArr): string { $strArr["foo"] .= "bar"; return $strArr["foo"]; } 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. bar($this->stuff); 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"]);
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(6) "foobar" }
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/vaCAp on line 10 Fatal error: Uncaught ArgumentCountError: Too few arguments to function Foo::foo(), 0 passed in /in/vaCAp on line 34 and exactly 1 expected in /in/vaCAp:19 Stack trace: #0 /in/vaCAp(34): Foo->foo() #1 {main} thrown in /in/vaCAp on line 19
Process exited with code 255.

preferences:
87.31 ms | 402 KiB | 123 Q