Home > Backend Development > PHP Tutorial > empty,isset,is_null comparison (1/4)_PHP tutorial

empty,isset,is_null comparison (1/4)_PHP tutorial

WBOY
Release: 2016-07-13 10:54:13
Original
903 people have browsed it

empty,isset,is_null I encountered some problems when using these functions. It even brings some security risks to your own programs. Many times, isset and empty are considered similar. Therefore, during development, I did not pay attention to it. When it was judged as a process, bug problems appeared.

1. Examples

a. A variable is not defined, how should we judge it?

view source print?
01 <?php
02 #不存在<font color="#aa7700">$test</font> 变量
03   
04 <font color="#aa7700">$isset</font>= isset(<font color="#aa7700">$test</font>)?<font color="#0000ff">"test is define!"</font>:<font color="#0000ff">"test is undefine!"</font>;
05 <font color="#ff1493">echo</font> <font color="#0000ff">"isset:$issetrn"</font>;
06   
07 <font color="#aa7700">$empty</font>=!<font color="#ff1493">empty</font>(<font color="#aa7700">$test</font>)?<font color="#0000ff">"test is define!"</font>:<font color="#0000ff">"test is undefine!"</font>;
08 <font color="#ff1493">echo</font> <font color="#0000ff">"empty:$emptyrn"</font>;
09   
10 <font color="#aa7700">$is_null</font>=<font color="#ff1493">is_null</font>(<font color="#aa7700">$test</font>)?<font color="#0000ff">"test is define!"</font>:<font color="#0000ff">"test is undefine!"</font>;
11 <font color="#ff1493">echo</font> <font color="#0000ff">"is_null:$is_nullrn"</font>;

The test result is:

empty,isset,is_null comparison (1/4)_PHP tutorial

The result is out: empty and isset will first check whether the variable exists, and then detect the variable value. And is_null just checks the variable value directly to see if it is null, so if the variable is not defined, an error will occur!

1 2 3 4

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632335.htmlTechArticleempty,isset,is_null I encountered some problems when using these functions. It even brings some security risks to your own programs. Many times, isset and empty are considered similar. So...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template