Isset and empty

Source: Internet
Author: User
Isset and empty if (isset ($ _ POST ["pageLimit"]) &! Empty ($ _ POST ["pageLimit"]) {
$ PageLimit = $ _ POST ["pageLimit"];
} Else {
$ PageLimit = 0;
}
Is the isset redundant,
Some people say
If the pagelimit field does not exist, an error is thrown when you use empty to determine whether the field exists,
Why can't I see the exception? do I still need to set php. ini?


Reply to discussion (solution)

You can set error_reporting to E_ALL.

You mean
If (! Empty ($ _ POST ["pageLimit"]) {
No exception?
Ini_set ('error _ report', E_ALL );
Now.

The biggest difference between empty and isset is that if empty is 0, true if (isset ($ _ POST ["pageLimit"]) is returned. &! Empty ($ _ POST ["pageLimit"]) {
$ PageLimit = $ _ POST ["pageLimit"];
} Else {
$ PageLimit = 0;
}
Is the isset redundant,
Some people say
If the pagelimit field does not exist, use empty to determine ......

You mean
If (! Empty ($ _ POST ["pageLimit"]) {
No exception?
Ini_set ('error _ report', E_ALL );
Now.









Ini_set ('error _ report', E_ALL );
If (empty ($ _ POST ["zz"]) {
Echo 1;
}
?>


It seems that no exception is thrown.

Ini_set ('error _ report', E_ALL );
Does not work? Then
Error_reporting (E_ALL );

Ini_set ('error _ report', E_ALL );
Does not work? Then
Error_reporting (E_ALL );

No changes,
You can test

Oh, it's changed. Earlier versions do not work.

If (isset ($ _ POST ["pageLimit"]) &! Empty ($ _ POST ["pageLimit"]) {
$ PageLimit = $ _ POST ["pageLimit"];
} Else {
$ PageLimit = 0;
}
According to your code, the previous one does not need to be written.
As mentioned above, empty (0) returns true, but your $ pageLimit = 0;, so isset can be removed completely.

When you learn a certain program, you will know the differences and advantages of the two.

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.