|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-11-19 07:54 UTC] josh dot ribakoff at gmail dot com
Description: ------------ Example A "compiles" and B does not (E_NOTICE). Invoking an array index on NULL *probably* warrants my attention more than doing so on an array. It has cost me countless hours, for one. Reproduce code: --------------- // A $foo = null; count( $foo['bar'] ); // B $foo = array(); count( $foo['bar'] ); Expected result: ---------------- 2 E_NOTICE errors Actual result: -------------- 1 E_NOTICE error PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Mon Feb 16 12:00:01 2026 UTC |
I disagree with your explanation because $foo['bar'] is never created as $foo still equals NULL according to my debugger. And to quote the manual: "Note: Attempting to access an array key which has not been defined is the same as accessing any other undefined variable: an E_NOTICE-level error message will be issued, and the result will be NULL. " I did RTFM, and it never said anything about trying to access a variable causing it to be created. The explanation left in the related bug you referenced is probably more accurate "Note: Accessing variables of other types using [] or {} silently returns NULL. " Even if this is "by design" I still think it should generate a NOTICE, where could I read about the design decisions of why it was done the way it was? And would it be appropriate to re-categorize this as a feature suggestion or do you guys not want to hear about it?