Bug #80572 [Com]: accessing array element that has an empty value does not work
| From: | rtrtrtrtrt at dfdfdfdf dot dfd | Date: | Fri, 01 Jan 2021 20:21:14 +0000 |
| Subject: | Bug #80572 [Com]: accessing array element that has an empty value does not work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231328@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80572&edit=1
ID: 80572
Comment by: rtrtrtrtrt at dfdfdfdf dot dfd
Reported by: gkroll at keldine dot ca
Summary: accessing array element that has an empty value does
not work
Status: Open
Type: Bug
Package: Session related
Operating System: all
PHP Version: 7.4.13
Block user comment: N
Private report: N
New Comment:
seriously - the two code snippets have *nothing* in common!
if you can't write a reproducer it makes no sense to report a bug based on what someone else
said - that guy need to add at least var_dump() at the critical codepath so that you see if your
assumptions what's in the array are true
and i bet they aren't
Previous Comments:
------------------------------------------------------------------------
[2021-01-01 20:16:02] gkroll at keldine dot ca
I do not personally have access to PHP 7.4, but one of the users of the software I am trying to
support reports:
ERROR 8: Trying to access array offset on value of type bool
0 Error occurred on line 209 of file ancestry_ctrl.php in function print_child_ascendancy
1 called from line 209 of file ancestry_ctrl.php in function print_child_ascendancy
The line in question follows:
$this->print_child_ascendancy($parents["HUSB"], $sosa*2, $depth-1);
The array element $parents["HUSB"] is set here:
if ($ct>0) {
$parents["HUSB"]=$match[1];
} else {
$parents["HUSB"]="";
}
In this case, $ct is zero.
Note: The array $parents is passed as a normal (not by reference) argument to the function where the
error occurs. This may have something to do with the problem.
------------------------------------------------------------------------
[2021-01-01 20:03:51] rtrtrtrtrt at dfdfdfdf dot dfd35
besides the description is *not* session related you have for sure *not* posted the code throwing
the error and "ERROR 8" comes anyways from somewhere else
[user@localhost:/downloads]$ php -v
PHP 7.4.14 (cli) (built: Dec 17 2020 21:58:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[user@localhost:/downloads]$ cat test.php
<?php declare(strict_types=1);
$xyz = array ('a'=>'value1', 'b'=>'',
'c'=>'value3');
var_dump ($xyz);
echo "\n";
if(isset($xyz['b']))
{
$foo = $xyz['b'];
}
$foo = $xyz['b'];
echo 'foo is set to:', $foo, ': end', "\n";
[user@localhost:/downloads]$ php test.php
array(3) {
["a"]=>
string(6) "value1"
["b"]=>
string(0) ""
["c"]=>
string(6) "value3"
}
foo is set to:: end
------------------------------------------------------------------------
[2021-01-01 19:58:15] girgias@php.net
Your test script works regardless of the PHP version: https://3v4l.org/SpuFW
So what is the actual issue (if any)?
------------------------------------------------------------------------
[2021-01-01 19:53:54] gkroll at keldine dot ca
Description:
------------
When an array element is set to the value '' (it's empty), any attempt to access the
value of that array element causes a nonsense error message:
ERROR 8: Trying to access array offset on value of type bool
Test script:
---------------
$xyz = array ('a'=>'value1', 'b'=>'',
'c'=>'value3');
var_dump ($xyz); echo '<br />'; // let's see what we have
if (isset($xyz['b'])) $foo = $xyz['b']; // no complaints here
$foo = $xyz['b']; // this crashes
echo 'foo is set to:', $foo, ': end', '<br />';
Expected result:
----------------
PHP 7.0 and earlier output:
array(3) { ["a"]=> string(6) "value1" ["b"]=> string(0)
"" ["c"]=> string(6) "value3" }
foo is set to:: end
I believe PHP 7.3 works too.
Actual result:
--------------
PHP 7.4 outputs:
ERROR 8: Trying to access array offset on value of type bool
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80572&edit=1