Bug #80902 [Opn->Nab]: is_null is not detecting nulls in array created via explode
| From: | cmb@php.net | Date: | Wed, 24 Mar 2021 11:18:47 +0000 |
| Subject: | Bug #80902 [Opn->Nab]: is_null is not detecting nulls in array created via explode | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232959@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80902&edit=1
ID: 80902
Updated by: cmb@php.net
Reported by: floriparob at gmail dot com
Summary: is_null is not detecting nulls in array created via
explode
-Status: Open
+Status: Not a bug
Type: Bug
Package: Strings related
Operating System: Debian 11
PHP Version: 7.4.16
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
See also <https://3v4l.org/jIB0J>.
Previous Comments:
------------------------------------------------------------------------
[2021-03-24 11:16:01] floriparob at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=80902&edit=1