<?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());
You have javascript disabled. You will not be able to edit any code.