Re: Implicit isset in ternary operator

From: Date: Thu, 02 Aug 2012 10:54:04 +0000
Subject: Re: Implicit isset in ternary operator
Groups: php.internals 
Request: Send a blank email to internals+get-61960@lists.php.net to get a copy of this message
Hi, Also in JavaScript if in strict mode. Legacy non-strict mode JS doesn't cause an error though. JS's || operator supresses this error though, which is great for e.g. x = x || new Object(); -- Sent from Samsung Mobile Andrew Faulds http://ajf.me/ Stas Malyshev <smalyshev@sugarcrm.com> wrote: 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

« previous php.internals (#61960) next »