Re: Implicit isset in ternary operator

From: Date: Wed, 01 Aug 2012 17:54:27 +0000
Subject: Re: Implicit isset in ternary operator
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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


Thread (31 messages)

« previous php.internals (#61930) next »