php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53094 Use '0' instead of '' as a result of converting boolean FALSE to string
Submitted: 2010-10-18 10:30 UTC Modified: 2010-10-18 19:18 UTC
Votes:3
Avg. Score:3.7 ± 1.9
Reproduced:2 of 3 (66.7%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: php-bugs at majkl578 dot cz Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php-bugs at majkl578 dot cz
New email:
PHP Version: OS:

 

 [2010-10-18 10:30 UTC] php-bugs at majkl578 dot cz
Description:
------------
I'd like to propose a change in converting booleans to string.
It'd be better if (string) FALSE returns '0' instead of empty string ('').
Why to do so?
 a) More logical behavior.
 b) Using booleans in output would be meaningful.
 c) Backward-compatible change - as documentation says: "This allows conversion back and forth between boolean and string values." - this behavior is not changed by this, because (bool) '0' is FALSE.

Test script:
---------------
<?php

echo (string) FALSE; //nothing now, '0' requested
var_dump((bool) '0'); //FALSE, no change
var_dump((string) FALSE === '0'); //FALSE, TRUE requested


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-18 19:18 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-10-18 19:18 UTC] rasmus@php.net
This would be extremely counterintuitive to most people since every language I 
know will return a zero-length string when boolean false is converted to a string.  
Having it return a non-zero length string would cause all sorts of backward 
compatibility problems as well.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 01:01:49 2024 UTC