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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 10:01:38 2025 UTC