3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); error_reporting(E_ALL); final class foo { private int $pageId = 0; private array $pageRecord = []; private bool $isListView = false; public static function forPage(int $pageId, bool $isListView = false): self { $foo = new self(); $foo->pageId = $pageId; $foo->pageRecord = ['uid' => 0, /* retrieved from database */]; $foo->isListView = $isListView; return $foo; } public function debug(): array { return [ 'pageId' => $this->pageId, 'pageRecord' => $this->pageRecord, 'isListView' => $this->isListView, ]; } } $test1 = new foo(); $test2 = $test1::forPage(1, true); $test3 = foo::forPage(1, true); var_dump($test2->debug()); var_dump($test3->debug());
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.36, 8.3.0 - 8.3.37, 8.4.1 - 8.4.28, 8.5.0 - 8.5.13, 8.6.0
array(3) { ["pageId"]=> int(1) ["pageRecord"]=> array(1) { ["uid"]=> int(0) } ["isListView"]=> bool(true) } array(3) { ["pageId"]=> int(1) ["pageRecord"]=> array(1) { ["uid"]=> int(0) } ["isListView"]=> bool(true) }

preferences:
21.69 ms | 1165 KiB | 6 Q