|
Web Contractors Web Developer Jobs Join Us / Log in Discussion |
avoiding PHP empty function
Submitted by rimian on Thu, 10/16/2008 - 11:12
Many PHP Developers avoid using the PHP empty function. This is because many believe it should return false in some cases where it returns true.
As you can see below empty() behaves as you would expect when passing arrays and strings but confusion begins when the string "0" is returned as TRUE. And why is TRUE considered not empty but FALSE is?
What the???
This function is doing too much work. You might have to use a condition like:
$myvar = '0';
return (empty($var) && ($myvar != '0'));
Empty() returns true when evaluating:
- "" (an empty string)
- 0 (0 as an integer)
- "0" (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- var $var; (a variable declared, but without a value in a class)
New forum topics
- [MELB] Web Developer | Web Designer | Graphic Designer | Marketing Manager
- Open Source Online Invoicing Software
- Professional Drupal Consulting, Design & Development Services in Australia
- New Year Speacial-Professional Website for 400$ with doamin+Host
- Ruby on Rails Oceana
- WebDev/Design/Research/Consultant - PHP/MySql, Javascript, Joomla, HTML, Flash, AJAX
- Freelance ASP.NET Developer
- System Monitoring with Nagios
- Learning Ruby? What about the RubyMentor Project?
- Need a team
- JAOO Sydney/Brisbane 2009
- Get Your Business a Website for $399 ONLY !!!
- Concrete5: Another CMS!
- Manage The Cloud with Amazon Web Services
- Crystal Reports developer needed


Post new comment