检查PHP中的变量is_undefined [英] Check if variable is_undefined in PHP

查看:71
本文介绍了检查PHP中的变量is_undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,我要检查是否尚未设置/定义变量,在其中将变量NULL设置为设置/定义的情况.

In PHP, I want to check if a variable has not been set/defined, where setting a variable NULL is considered set/defined.

我知道这里的所有内容: http://php.net/manual/en/types.comparisons.php 包括isset(),empty()和is_null().这些似乎都不是我要找的东西.考虑以下示例:

I'm aware everything here: http://php.net/manual/en/types.comparisons.php including isset(), empty(), and is_null(). None of these appear to be what I'm looking for. Consider the following example:

<?php 
$myNull = null;
echo 'isset($myNull): "'.isset($myNull).'"<br />';
echo '$myNull value = "'.$myNull . '"<br />';

echo "<br />";

echo 'isset($myUndefined): "'.isset($myUndefined).'"<br />';
echo '$myUndefined value = "'.$myUndefined . '"<br />';
?>

此示例输出如下内容:
isset($ myNull):"
$ myNull value ="

This example outputs something like:
isset($myNull): ""
$myNull value = ""

isset($ myUndefined):"
注意:未定义变量:第9行的C:\ wamp \ www \ plm \ temp4.php中的myUndefined
$ myUndefined value ="

isset($myUndefined): ""
Notice: Undefined variable: myUndefined in C:\wamp\www\plm\temp4.php on line 9
$myUndefined value = ""

我想知道变量是否为未定义,如上面在通知中所述.我想要一个函数,称它为"is_undefined",其中

I want to know if a variable is Undefined as it says above in the notice. I want a function, call it "is_undefined", where

$myNull = null;
is_undefined($myNull); // is false
is_undefined($myUndefined); // is true

有人吗?预先感谢.

推荐答案

我还没有使用过-但我认为"get_defined_vars"应该值得一看... http://php.net/manual/en/function.get-defined-vars.php

I haven´t used it yet - but I think that "get_defined_vars" should be worth a look... http://php.net/manual/en/function.get-defined-vars.php

我会尝试转储结果.

这篇关于检查PHP中的变量is_undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆