var 是否设置为与 undefined 相同的 null 以及如何检查差异 [英] Is var set to null same as undefined and how to check differences

查看:44
本文介绍了var 是否设置为与 undefined 相同的 null 以及如何检查差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单问题:在 php 中,var 是否设置为 null 与 undefined 相同?

Simple question: In php, is var set to null same as undefined?

另外,最简单的检查方法是var null是什么?

In addition, what is simplest way to check is var null?

如何在不破坏代码的情况下使用此功能,例如.通过在配置数组中设置一些可以设置为 null 的可选内容.

How to use this functionality without breaking code, eg. by setting something optional in config array that can be set to null.

如果使用 is_null 检查 null,如果没有定义 var,它可能会破坏代码.

If check for null with is_null it can potentially break code if var is not defined.

is_nullisset 完全相反,但仅当您确定定义了 var 时才能使用.Fore 所有其他情况看起来 isset 更合适.

is_null is completely opposite of isset, but can used only and only if you are certain that var is defined. Fore every other cases looks that isset more appropriate.

并检查nullisset 是不合适的,吗?

And to check null, isset is unapropriate, is it?

所以 var 可以是:

So var can be:

  • 未定义
  • 带有要检查的内容 is_* 函数(numericstringarray、...)
  • undefined
  • null
  • empty
  • with content to check with is_* functions (numeric, string, array,...)

推荐答案

var set to NULL 与 undefined 不同.

var set to NULL is not the same as undefined.

<?php
if (is_null($undefinedvariable)) {
    echo 'This variable is NULL';
}

此代码演示了可能会如何引起混淆,因为它会导致显示消息此变量为 NULL",但也会生成未定义变量"通知.(当然,假设 $undefinedvariable 实际上是 undefined!)

This code demonstrates how confusion may arise, as it will result in the message 'This variable is NULL' being displayed, however it will also generate an "Undefined variable" notice. (assuming $undefinedvariable is actually undefined of course!)

这篇关于var 是否设置为与 undefined 相同的 null 以及如何检查差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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