php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76923 null comparing to string '0'
Submitted: 2018-09-23 16:09 UTC Modified: 2018-09-23 18:03 UTC
From: gegpcoder at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.3.0RC1 OS: all
Private report: No CVE-ID: None
 [2018-09-23 16:09 UTC] gegpcoder at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.types.null
---

if '0' is false when converted to boolean and null is false as well
why 
0==null is true
false==null is true
'' ==null is true 
array()==null is true

but '0' == null is false 

Test script:
---------------
<?php
echo null == 0; //true
echo null == array(); //true
echo null == ''; //true
echo null == '0'; //false
?>


Expected result:
----------------
1111

Actual result:
--------------
111

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-23 16:33 UTC] spam2 at rhsoft dot net
what at http://www.php.net/en/language.types.null akes you believe '0' shou,d be the same as NULL?

'0' is NOT an empty string, it's a string which just the char 0 in it
so when '0' is not empty why should it be the same as NULL
 [2018-09-23 18:03 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-09-23 18:03 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

http://php.net/manual/en/language.types.type-juggling.php
http://php.net/manual/en/types.comparisons.php

It's far too late to change this behavior.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC