3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SomeClass { private $myData = [ 'test1' => 'a value!', 'test2' => null, ]; public function __get($name) { if (!array_key_exists($name, $this->myData)) { echo "oops, $name does not exist"; return null; } return $this->myData[$name]; } public function __isset($name) { return isset($this->myData[$name]); } } $s = new SomeClass; // this is fine, we try reading stuff and in last case, it's "not possible" echo "test1 is $s->test1"; echo "test2 is $s->test2"; echo "testX is $s->testX"; // let's check if our properties exist echo 'test1 ' . (isset($s->test1) ? 'is set' : 'is not set') . PHP_EOL; echo 'test2 ' . (isset($s->test2) ? 'is set' : 'is not set') . ' (but that\'s ok)' . PHP_EOL; echo 'testX ' . (isset($s->testX) ? 'is set' : 'is not set') . ' (but that\'s also ok)' . PHP_EOL; echo 'test2 ' . (property_exists($s, 'test2') ? 'exists' : 'is not there') . ' (yeah, strictly speaking)' . PHP_EOL; echo 'testX ' . (property_exists($s, 'testX') ? 'exists' : 'is not there') . ' (ok... so how do I know it\'s really not there?)' . PHP_EOL;

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
158.61 ms | 2637 KiB | 11 Q