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
 [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-2022 The PHP Group
All rights reserved.
Last updated: Thu Aug 11 09:06:03 2022 UTC