|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71400 null assignment as array strange results
Submitted: 2016-01-17 22:39 UTC Modified: 2019-10-25 15:45 UTC
Avg. Score:3.8 ± 0.8
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: rav dot janisz at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Arrays related
PHP Version: 5.5.31 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
27 + 39 = ?
Subscribe to this entry?

 [2016-01-17 22:39 UTC] rav dot janisz at gmail dot com
null assignment to a variable and refer to it as an array element does not return any errors

after assign null to variable var_dump return null and isset return false, but why in line 5 assign first element of $zonk variable(which is don't array and don't should exists at all) to next variable doesnt't return any errors

Test script:
$zonk = null;            //1
var_dump($zonk);         //2 return null
var_dump(isset($zonk));  //3 return false

$beret = $zonk[0];       //5 don't throw nothing ???
var_dump($beret);        //6 return null
var_dump(isset($beret)); //7 return false

Expected result:
is line 6 don't should throw something to output error or notice?
or if it is good behavior then in line 3 isset should return true?
or if i'm wrong explain why? becouse i can't figured it out


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-17 22:57 UTC] rav dot janisz at gmail dot com
-Summary: tested on 5.5.29 php version +Summary: null assignment as array strange results
 [2016-01-17 22:57 UTC] rav dot janisz at gmail dot com
wrong summary
 [2019-10-25 15:36 UTC] amir dot rajs at gmail dot com
This bug needs to be fixed ASAP. The fact that PHP 7 doesn't throw error when trying to access a null or numeric value as an associative array with string index is bit outdated. It should first check if the value is array, and throw error if accessing non-array as an array.
 [2019-10-25 15:45 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2019-10-25 15:45 UTC]
This will throw a notice in PHP 7.4.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Aug 07 04:01:25 2020 UTC