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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

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: Thu Jul 03 06:01:34 2025 UTC