PHP: empty("0") - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Missing functions Initializers

Last updated: Sat, 27 Jan 2007

view this page in

# `empty("0")`

The perhaps most controversial change in behavior has happened to the behavior of the empty(). A String containing only the character '0' (zero) is now considered empty while it wasn't in PHP 3.

This new behavior makes sense in web applications, with all input fields returning strings even if numeric input is requested, and with PHP's capabilities of automatic type conversion. But on the other hand it might break your code in a rather subtle way, leading to misbehavior that is hard to track down if you do not know about what to look for.

add a note User Contributed Notes
empty("0")
alan at frostick dot de
02-Dec-2001 10:01
`The changes to empty() also affect isset() in a similar way.
Under php3:
$foo=""; isset($foo) returned false..
but under php4 it returns true, because the variable is defined.
I discovered this when converting other people's code to php4. They used isset() unnecessarily - with the implicit expectation it just tested the value of the variable as being non-null. Although I don't agree with sloppy coding, it can give an unexpected shock when run under php4 and so any uses of isset() should be searched for before you attempt to migrate.`
add a note
Missing functions Initializers

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST