Bug #71400 [Opn->Csd]: null assignment as array strange results

From: Date: Fri, 25 Oct 2019 15:45:49 +0000
Subject: Bug #71400 [Opn->Csd]: null assignment as array strange results
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223463@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71400&edit=1

 ID:                 71400
 Updated by:         nikic@php.net
 Reported by:        rav dot janisz at gmail dot com
 Summary:            null assignment as array strange results
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Arrays related
 Operating System:   linux
 PHP Version:        5.5.31
-Assigned To:        
+Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

This will throw a notice in PHP 7.4.


Previous Comments:
------------------------------------------------------------------------
[2019-10-25 15:36:31] 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.

------------------------------------------------------------------------
[2016-01-17 22:57:07] rav dot janisz at gmail dot com

wrong summary

------------------------------------------------------------------------
[2016-01-17 22:39:57] 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



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71400&edit=1


Thread (4 messages)

« previous php.bugs (#223463) next »