3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Hoge { const CONST_FOO = 'foo'; public function __construct() { // 定数が存在する場合 print constant('self::CONST_FOO') . PHP_EOL; // PHP8以降では定数が存在しない場合は例外が送出される try { print constant('self::NOT_EXIST'); } catch (Error $e) { print $e->getMessage(); print $e->getTraceAsString(); } } } $obj = new Hoge();

preferences:
24.28 ms | 402 KiB | 5 Q