3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface HasTest { public function test(); } class TestClass implements HasTest { public function test() { return 'This is a quick test'; } } $test = array ( 'test' => TestClass ); // !! Using instanceof var_dump($test['test'] instanceof HasTest); var_dump(TestClass instanceof HasTest); // !! Using class_implements var_dump(in_array('HasTest', class_implements($test['test']))); /** * Output: * * bool(false) * bool(false) * bool(true) */ $class = new $test['test']; var_dump($class instanceof HasTest); /** * Output: * bool(true) */
Output for 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
Fatal error: Uncaught Error: Undefined constant "TestClass" in /in/QTm9L:14 Stack trace: #0 {main} thrown in /in/QTm9L on line 14
Process exited with code 255.
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant TestClass - assumed 'TestClass' (this will throw an Error in a future version of PHP) in /in/QTm9L on line 14 bool(false) Warning: Use of undefined constant TestClass - assumed 'TestClass' (this will throw an Error in a future version of PHP) in /in/QTm9L on line 20 bool(false) bool(true) bool(true)
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
Notice: Use of undefined constant TestClass - assumed 'TestClass' in /in/QTm9L on line 14 bool(false) Notice: Use of undefined constant TestClass - assumed 'TestClass' in /in/QTm9L on line 20 bool(false) bool(true) bool(true)
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Notice: Use of undefined constant TestClass - assumed 'TestClass' in /in/QTm9L on line 15 bool(false) Notice: Use of undefined constant TestClass - assumed 'TestClass' in /in/QTm9L on line 20 bool(false) bool(true) bool(true)

preferences:
96.24 ms | 2416 KiB | 4 Q