php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #31302 empty() shouldn't count ' ', '\n', etc
Submitted: 2004-12-26 07:43 UTC Modified: 2004-12-27 00:57 UTC
From: aitrus at tresgeek dot net Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.3.10 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-12-26 07:43 UTC] aitrus at tresgeek dot net
Description:
------------
I thought that this used to be the behavior of empty()...

It would be nice of empty() returned true when passed a string which only had spaces, tabs, or newline characters in it.


Reproduce code:
---------------
$foo = ' ';

if ( empty( $foo ) ) {
  echo "foo is empty";
} else {
  echo "foo is NOT empty";
}//if

---

output is: 'foo is NOT empty'

Expected result:
----------------
expected output: 'foo is empty'


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-26 11:32 UTC] derick@php.net
We can't change this due to BC reasons, also, it doesn't fit a particular language construct (empty is NOT a function!)
 [2004-12-27 00:57 UTC] aitrus at tresgeek dot net
I realize it isn't a function (took a couple time of saying empty( someFn( ) ) to get that through to me)... I haven't, however, looked at the source for empty() so I'm don't know what it's BC is (or what the issue is).

The issue I run into is one of (html) input validation.  With the behavior of trim() (per our short conversation on bug #31302) it doesn't seem that there is a clean, efficient way of checking for people entering a string of spaces or non-breaking spaces ( ) in the place of legit input.

Am I missing something completely?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 13:01:31 2024 UTC