Bug #80902 [NEW]: is_null is not detecting nulls in array created via explode

From: Date: Wed, 24 Mar 2021 11:16:01 +0000
Subject: Bug #80902 [NEW]: is_null is not detecting nulls in array created via explode
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232958@lists.php.net to get a copy of this message
From:             floriparob at gmail dot com
Operating system: Debian 11
PHP version:      7.4.16
Package:          Strings related
Bug Type:         Bug
Bug description:is_null is not detecting nulls in array created via explode

Description:
------------
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:
---------------
<?php

$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 {
	echo "NOT AN ARRAY" . PHP_EOL;
}
?>




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

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80902&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80902&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80902&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80902&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80902&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80902&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80902&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80902&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80902&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80902&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80902&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80902&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80902&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80902&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80902&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80902&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80902&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80902&r=mysqlcfg


Thread (2 messages)

« previous php.bugs (#232958) next »