Php checks whether the variable is empty.

Source: Internet
Author: User
If you retrieve the value from the database and determine whether it is null, it looks very simple. You only need to compare it with null. Otherwise, if ($ objnull) {} will return an error in this case: notice: Tryingtogetpropertyofnon-objectproblem. Check whether the following code is required: if (isset ($ obj) {e

Retrieve the value from the database and determine whether it is null. This looks very simple. You only need to compare it with null. In fact, if ($ obj = null) {} in this case, an error will be reported: Notice: Trying to get property of non-object problem. After checking, we found that the following method is required: if (isset ($ obj) {e

If it is null after the value is retrieved from the database, it looks very simple. You only need to compare it with null. In fact, it is not,

if($obj==null){ } 

In this case, the following error occurs: Notice: Trying to get property of non-object problem,

I checked and found that the following statement is required:

if (isset($obj)) { echo "This var is set set so I will print."; } 

What is this isset?

The isset function checks whether variables are set.

Format: bool isset (mixed var [, mixed var [,...])

Return Value:

If the variable does not exist, FALSE is returned.
If the variable exists and its value is NULL, FALSE is returned.
If the variable exists and the value is not NULL, true is returned.
When multiple variables are checked at the same time, TRUE is returned only when each individual item meets the previous requirement; otherwise, the result is FALSE.
If unset () is used to release a variable, it will no longer be isset (). If you use isset () to test a variable that is set to NULL, FALSE is returned. Note that a NULL byte ("\ 0") is not equivalent to the NULL constant of PHP.

Warning: isset () can only be used for variables, because passing any other parameter will cause a parsing error. To check whether a constant has been set, use the defined () function.

It seems that the problem with my judgment just now is that "it is a NULL byte (" \ 0 ") and not equivalent to the NULL constant of PHP ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.