Bug #52184 [Com]: Using null as array gives no warning or error

From: Date: Fri, 25 Jun 2010 22:04:26 +0000
Subject: Bug #52184 [Com]: Using null as array gives no warning or error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-151873@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52184&edit=1 ID: 52184 Comment by: egorinsk at gmail dot com Reported by: egorinsk at gmail dot com Summary: Using null as array gives no warning or error Status: Bogus Type: Bug Package: *General Issues Operating System: linux PHP Version: 5.3.2 New Comment: Thank you for your response. > You aren't accessing an array offset but a string offset. null is casted to String. The string is shorter than the offset (length is 0) so it returns NULL. Well, PHP emits a notice when accessing uninitialized string offset, so this is not the case: ~: php -r 'error_reporting(E_ALL); $a=""; echo $a[12]; ' PHP Notice: Uninitialized string offset: 12 in Command line code on line 1 PHP Stack trace: PHP 1. {main}() Command line code:0 Notice: Uninitialized string offset: 12 in Command line code on line 1 Call Stack: 0.0002 317032 1. {main}() Command line code:0 Anyway, I guess there should be at least warning, because null is neither a string, nor array, and trying to access element of null is obviously an error, and I, as a developer, would prefer to have it logged. Previous Comments: ------------------------------------------------------------------------ [2010-06-25 15:25:41] johannes@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php You aren't accessing an array offset but a string offset. null is casted to String. The string is shorter than the offset (length is 0) so it returns NULL. ------------------------------------------------------------------------ [2010-06-25 13:39:14] egorinsk at gmail dot com Description: ------------ Using null as array gives no warning, notice or error, just returns null. It is at least strange. Test script: --------------- <?php error_reporting(E_ALL); $a = null; echo $a[12]; // Gives no warning, notice or error ?> Expected result: ---------------- Some kind of notice or warning. Actual result: -------------- (nothing) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52184&edit=1

« previous php.bugs (#151873) next »