<?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();
You have javascript disabled. You will not be able to edit any code.