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;
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 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
test1 is a value!test2 is oops, testX does not existtestX is test1 is set test2 is not set (but that's ok) testX is not set (but that's also ok) test2 is not there (yeah, strictly speaking) testX is not there (ok... so how do I know it's really not there?)

preferences:
115.72 ms | 2018 KiB | 4 Q