php.net |  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
Votes:4
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rav dot janisz at gmail dot com
New email:
PHP Version: OS:

 

 [2016-01-17 22:39 UTC] rav dot janisz at gmail dot com
Description:
------------
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


Patches

Pull Requests

History

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] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2019-10-25 15:45 UTC] nikic@php.net
This will throw a notice in PHP 7.4.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 04:01:36 2025 UTC