Bug #65310 [Opn->Dup]: PHP generates no error when calling a NULL variable as array
Edit report at https://bugs.php.net/bug.php?id=65310&edit=1
ID: 65310
Updated by: nikic@php.net
Reported by: tschoonen at gmail dot com
Summary: PHP generates no error when calling a NULL variable
as array
-Status: Open
+Status: Duplicate
Type: Bug
Package: *General Issues
Operating System: Ubuntu 13.04x64
PHP Version: 5.4.17
Block user comment: N
Private report: N
New Comment:
Closing as duplicate of https://bugs.php.net/bug.php?id=64194.
Previous Comments:
------------------------------------------------------------------------
[2013-07-22 10:17:28] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65310&edit=1
Thread (2 messages)