RE: [PHP] Associative Array key funkyness
| From: | Zeev Suraski | Date: | Sat, 29 Jul 2000 21:32:43 +0000 |
| Subject: | RE: [PHP] Associative Array key funkyness | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8994@lists.php.net to get a copy of this message | ||
At 00:12 29/07/2000, Boget, Chris wrote:
Outside of a string, $foo[bar] is an invalid syntax. PHP recognizes it, though, and warns you about this with an E_NOTICE warning. Whether or not this warning is displayed, depends on your error_reporting settings. So, while it is invalid, it still works because PHP understands what you mean by it, correct? So if you have the reporting settings low enough you don't get a warning, but are there other repurcussions to doing things like this? I do this all the time, both in assigning and displaying data and I just want to make sure I'm not causing any underlying problems...Basically, yes to all of your questions. The major downside to using this approach is that we make no promises as to what words may end up being keywords tomorrow. So, in your example, if 'bar' becomes a keyword tomorrow, your code will no longer work, unless you modify it to read $foo["bar"]. Because keywords have no meaning inside quoted strings, this is not a problem there. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/