3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** @template T of string|null */ class StringOrNull { /** @var T */ public ?string $value; /** @param T $value */ public function __construct(?string $value) { $this->value = $value; } /** * @template T2 of string|int * @param T2 $value * @psalm-this-out self<T2> */ public function setFromStringOrInt(string|int $value): void { if (is_string($value)) { // This is a separate issue, probably https://github.com/vimeo/psalm/issues/7739 $this->value = $value; } } } class Foo { /** @var list<StringOrNull<null>> */ private array $nulls = []; /** @param list<StringOrNull<null>> $nulls */ public function __construct(array $nulls) { $this->nulls = $nulls; } public function assertAllNull(): void { foreach ($this->nulls as $null) { assert($null->value === null); } } } $stringOrNull = new StringOrNull(null); $foo = new Foo([$stringOrNull]); $stringOrNull->setFromStringOrInt("foobar"); $foo->assertAllNull();
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught AssertionError: assert($null->value === null) in /in/mKN4o:41 Stack trace: #0 /in/mKN4o(41): assert(false, 'assert($null->v...') #1 /in/mKN4o(49): Foo->assertAllNull() #2 {main} thrown in /in/mKN4o on line 41
Process exited with code 255.

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:
52.19 ms | 405 KiB | 5 Q