php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65310 PHP generates no error when calling a NULL variable as array
Submitted: 2013-07-22 10:17 UTC Modified: 2013-07-22 11:12 UTC
From: tschoonen at gmail dot com Assigned:
Status: Duplicate Package: *General Issues
PHP Version: 5.4.17 OS: Ubuntu 13.04x64
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: tschoonen at gmail dot com
New email:
PHP Version: OS:

 

 [2013-07-22 10:17 UTC] tschoonen at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.types.array
---
I accidentally discovered that when you try to call a NULL variable as an array, PHP will simply return NULL without triggering any form of error.
I don't believe that this is intended behaviour, as calling an undefined offset in an array causes a warning. 

My sincere apologies if this bug has been reported earlier, I spent quite a while searching in and outside of php.net to no avail.

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

error_reporting(-1);

$array = array();

// This will return NULL and trigger an 'undefined offset' notice.
var_dump($array[1]);

// This will return NULL and trigger an 'undefined variable' notice.
var_dump($undefined[3]); 
var_dump($undefined[1]);

$null_var = null;

// This, however, will return NULL and give no error.
var_dump($null_var[1]);

Expected result:
----------------
PHP Notice:  Undefined offset: 1 in /var/www/null.php on line 8
NULL
PHP Notice:  Undefined variable: undefined in /var/www/null.php on line 11
NULL
PHP Notice:  Undefined variable: undefined in /var/www/null.php on line 12
NULL
NULL


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-22 11:12 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2013-07-22 11:12 UTC] nikic@php.net
Closing as duplicate of https://bugs.php.net/bug.php?id=64194.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 13:01:30 2025 UTC