3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private $_locations = array(); public $test = array(); private $_test = array(); public function getResult() { var_dump($this->_locations = true); // works var_dump($this->_locations = "test"); // works var_dump($this->_locations = array()); // works var_dump($this->_locations = array("test")); // produces a critical error var_dump($this->_locations = array("test" => "test")); // produces a critical error var_dump($this->_locations[] = "test"); // produces a critical error var_dump($this->_locations["test"] = "test"); // produces a critical error var_dump($test = array("test" => "test")); // works var_dump($this->test = array()); // works var_dump($this->test = array("test")); // works var_dump($this->_test = array()); // works var_dump($this->_test = array("test")); // works } } $obj = new A(); $obj->getResult();
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
bool(true) string(4) "test" array(0) { } array(1) { [0]=> string(4) "test" } array(1) { ["test"]=> string(4) "test" } string(4) "test" string(4) "test" array(1) { ["test"]=> string(4) "test" } array(0) { } array(1) { [0]=> string(4) "test" } array(0) { } array(1) { [0]=> string(4) "test" }

preferences:
91.71 ms | 1296 KiB | 4 Q