php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65484 Accessing null variable as array over key
Submitted: 2013-08-20 08:02 UTC Modified: 2015-06-08 20:51 UTC
Votes:8
Avg. Score:3.9 ± 0.9
Reproduced:3 of 4 (75.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: jan dot kahoun at heureka dot cz Assigned: cmb (profile)
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.5.2 OS:
Private report: No CVE-ID: None
 [2013-08-20 08:02 UTC] jan dot kahoun at heureka dot cz
Description:
------------
If you define variable as NULL and then you want to acces it over keys as array 
like $array['kolo'] then PHP should trigger a strict error and not return the NULL.

Test script:
---------------
<?php

$array = null;
var_dump($array['kolo']);

/* 
Expected result:
PHP strict error

Actual result:
NULL
*/


Expected result:
----------------
Expected is PHP strict error.

Actual result:
--------------
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-20 08:33 UTC] requinix@php.net
-Package: *General Issues +Package: Scripting Engine problem -PHP Version: Irrelevant +PHP Version: 5.5.2
 [2013-08-20 08:33 UTC] requinix@php.net
See also
bug #37676 using Array access operator [] on boolean variable does not show Notice
bug #40692 Trying to use boolean as array doesn't give an error

and a part of
bug #62769 Inconsistent notice reporting using []
 [2014-02-16 00:32 UTC] salsi at icosaedro dot it
error_reporting(-1);
$arr = NULL;
var_dump($arr[0]);

==> NULL !!! no warnings at all!

Tested with:
PHP 5.3.10
PHP 5.5.9
 [2015-06-08 20:51 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2015-06-08 20:51 UTC] cmb@php.net
Duplicate of request #37676.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Aug 18 17:01:27 2019 UTC