|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80902 is_null is not detecting nulls in array created via explode
Submitted: 2021-03-24 11:16 UTC Modified: 2021-03-24 11:18 UTC
From: floriparob at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Strings related
PHP Version: 7.4.16 OS: Debian 11
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.
Block user comment
Status: Assign to:
Bug Type:
From: floriparob at gmail dot com
New email:
PHP Version: OS:


 [2021-03-24 11:16 UTC] floriparob at gmail dot com
Version: 7.4.15-5+deb11u1

When you explode a string into an array, elements that contain nothing (null) are detectable as such via is_null.
The only way to tell is any array element doesn't contain a value is to
strlen(trim($a_array[2])) == 0, which gives you the result you want, but is a tad tedious. 
I'm sure in prior versions is_null($a_array[2] would return true when that array element is empty.
I cannot prove or disprove this as I don't have access to an older version of PHP.

Test script:

$a_string = "awsed|34r5|||gh||";
$a_array  = explode ("|", $a_string);
if (is_array($a_array)) {
	$a_count = count($a_array);
	echo "Number of Elements " . $a_count . PHP_EOL;
	for ($i = 0; $i < $a_count; $i++) {
		if (is_null($a_array[$i])) {
			echo "Element " . $i . " Is NULL" . PHP_EOL;
		} else {
			echo "Element " . $i . " is " . $a_array[$i] . PHP_EOL;
} else {

Expected result:
Number of Elements 7
Element 0 is awsed
Element 1 is 34r5
Element 2 Is NULL 
Element 3 Is NULL
Element 4 is gh
Element 5 Is NULL
Element 6 Is NULL

Actual result:
Number of Elements 7
Element 0 is awsed
Element 1 is 34r5
Element 2 is 
Element 3 is 
Element 4 is gh
Element 5 is 
Element 6 is


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-24 11:18 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-03-24 11:18 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

See also <>.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Mar 03 10:01:29 2024 UTC