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 this is not your bug, you can add a comment by following this link.
If this is your bug, but 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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Thu Nov 14 17:01:35 2019 UTC