▽1
●
oil999 ●200ポイント ベストアンサー |
コメントをありがとうございます。
回答を訂正しました。
issetを正しく理解する。null値とunsetの違い-PHP変数管理(http://www.cpa-lab.com/tech/097)に書いてあるように、PHPでは未定義とNULL代入の区別が難しいので、次のようなコードが最も短い形になると思います。
結果は変数$_is_nodefineに、未定義ならTRUEが、それ以外ならFALSEが入ります。
PHPの性質上、この処理を関数やクラスにすることができません。
<?php function _myErrorHandler($errno, $errmsg, $filename, $linenum, $vars) { global $_is_nodefine; if ($errno | E_WARNING)$_is_nodefine = TRUE; } //$a = NULL; //$a = '1'; $old_error_reporting = error_reporting(E_ALL); $_is_nodefine = FALSE; $old_error_handler = set_error_handler('_myErrorHandler'); is_null($a); if (! is_null($old_error_handler))set_error_handler($old_error_handler); error_reporting($old_error_reporting); var_dump($_is_nodefine); ?>