MIKESTOWE.COM

you are here

Weekly PHP Test

In PHP empty(array()) returns true, where-as empty(array(1)) returns false. What does the following code produce in PHP 5.0+

PHP
1
2
3
4
5
6
$var = (object) array();
if(empty($var)) {
die('Is Empty');
} else {
die('Is Not Empty');
}

.

.

.

.

.

.

ANSWER:

Is Not Empty

In PHP 5.0+ empty no longer declares an object with no properties as empty. Instead all objects return false when checked, even though it is being built by an empty array which returns true.

.

PHP Manual:
http://php.net/manual/en/function.empty.php

Share this Page:
Facebook Twitter Linkedin Reddit Tumblr Email

Leave a Reply

Your email address will not be published. Required fields are marked *