3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=0); class Test { private array $array; private string $string; public function __construct() { // $this->array = 1; // Fatal error $this->array = (array) 1; // ok, [1] $this->string = 1; // ok, '1' } public function getArray(): array { return $this->array; // ok } public function getAnotherArray(): array { // return 1; // Fatal error return (array) 1; // ok, [1] } public function getString(): string { return $this->string; } } $test = new Test(); var_dump($test->getArray(), $test->getAnotherArray(), $test->getString());

preferences:
28.09 ms | 404 KiB | 5 Q