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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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 Mar 28 21:01:27 2024 UTC