|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-06-25 13:39 UTC] 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) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 04:00:01 2025 UTC |
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.