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