Hi!

> I've looked a bit into other languages (Ruby, Python, Go) and
> all of them do not generate an error when an undefined dict/hash/map key is 
> accessed.

Python would definitely throw an exception:

>>> a = {}
>>> a
{}
>>> print a['a']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'a'

And it's just as annoying as in PHP. Actually, probably more annoying
:). But it has .get() which solves the problem usually, albeit in a bit
more verbose way. Also, Python has defaultdict which I would usually use
when I need keys to be created automatically.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to