php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60402 "0.0" (0.0 as a string) values are considered as not empty
Submitted: 2011-11-28 14:44 UTC Modified: 2011-12-01 08:51 UTC
Votes:2
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: alagar86 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.8 OS: Windows/Linux
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
44 - 40 = ?
Subscribe to this entry?

 
 [2011-11-28 14:44 UTC] alagar86 at gmail dot com
Description:
------------
Hi PHP team. 

For empty() we have the following rule :
The following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)

But values like  "0.0" are cosidered as not empty for example :
$zeroFloatString = "0.0"; (0.0 as a string) 
var_dump(empty($zeroFloatString));  prints false .  However the $zeroFloatString contains "0.0" value. 

Thanks, 
Anton


Test script:
---------------
$emptyString = ""; (an empty string)
$zeroInt = 0; (0 as an integer)
$zeroFloat = 0.0; (0 as a float)
$zeroString = "0"; (0 as a string)
$zeroFloatString = "0.0"; (0.0 as a string)

var_dump(empty($emptyString)); true
var_dump(empty($zeroInt)); true 
var_dump(empty($zeroFloat)); true 
var_dump(empty($zeroString)); true
var_dump(empty($zeroFloatString)); false 

Expected result:
----------------
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)

Actual result:
--------------
bool(true)
bool(true)
bool(true)
bool(true)
bool(false) //   var_dump(empty($zeroFloatString))  where $zeroFloatString = "0.0"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-30 16:36 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2011-11-30 16:36 UTC] cataphract@php.net
The manual says 0.0 (i.e. the same as 0., or (float) 0), not "0.0" (a string).

Closing as bogus.
 [2011-12-01 08:51 UTC] alagar86 at gmail dot com
I agree that manual doesn't say about "0.0" (a string). But we have the following situation:
$zeroFloatString = "0.0"; (0.0 as a string)
$zeroFloat = 0.0; (0 as a float)
var_dump($zeroFloatString == $zeroFloat); // true
var_dump(empty($zeroString)); true
var_dump(empty($zeroFloatString)); false 

I  think it isn't normal. If A == B, why f(A) != f(B) ?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 17:01:31 2024 UTC