3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { private File $file { get => $this->file ??= new File($this->test1 . '-' . $this->test2 . '-' . random_int(0, PHP_INT_MAX)); } public function __construct( public string $test1, public string $test2, ) { } public function doStuffA() { var_dump($this->file->file . ' ~ A'); } public function doStuffB() { var_dump($this->file->file . ' ~ B'); } } class File { public function __construct( public string $file, ) { } } $t = new Test('a', 'b'); $t->doStuffA(); $t->doStuffB(); $t->doStuffA(); $t->doStuffB();
Output for 8.4.5
string(27) "a-b-2646375680958721823 ~ A" string(27) "a-b-2646375680958721823 ~ B" string(27) "a-b-2646375680958721823 ~ A" string(27) "a-b-2646375680958721823 ~ B"
Output for 8.4.4
string(27) "a-b-1080005485051034318 ~ A" string(27) "a-b-1080005485051034318 ~ B" string(27) "a-b-1080005485051034318 ~ A" string(27) "a-b-1080005485051034318 ~ B"
Output for 8.4.3
string(27) "a-b-1371714812081212732 ~ A" string(27) "a-b-1371714812081212732 ~ B" string(27) "a-b-1371714812081212732 ~ A" string(27) "a-b-1371714812081212732 ~ B"
Output for 8.4.2
string(27) "a-b-8949592988069335616 ~ A" string(27) "a-b-8949592988069335616 ~ B" string(27) "a-b-8949592988069335616 ~ A" string(27) "a-b-8949592988069335616 ~ B"
Output for 8.4.1
string(27) "a-b-8322566143547569984 ~ A" string(27) "a-b-8322566143547569984 ~ B" string(27) "a-b-8322566143547569984 ~ A" string(27) "a-b-8322566143547569984 ~ B"
Output for 8.1.32, 8.2.0 - 8.2.28, 8.3.0 - 8.3.19
Parse error: syntax error, unexpected token "{", expecting "," or ";" in /in/pjSlu on line 5
Process exited with code 255.

preferences:
162.99 ms | 968 KiB | 7 Q