php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79859 Array with null is true
Submitted: 2020-07-14 15:00 UTC Modified: 2020-07-14 15:01 UTC
From: giolaza at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.2.32 OS: WIN 10
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: giolaza at gmail dot com
New email:
PHP Version: OS:

 

 [2020-07-14 15:00 UTC] giolaza at gmail dot com
Description:
------------
Array with first element null is true

Test script:
---------------
$arr = [ 0 => null];
if ($arr) {
    echo 'is true';
} else {
    echo 'is false';
}

//TEST 2 
$arr = explode(',', null);
if ($arr) {
    echo 'is true';
} else {
    echo 'is false';
}

Expected result:
----------------
is false

Actual result:
--------------
is true

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-14 15:01 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2020-07-14 15:01 UTC] nikic@php.net
Any non-empty array is true under a bool cast.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC