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
2012/8/2 Andrew Faulds ajf@ajf.me:
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();
Could be cool to make this in PHP with the 'or' operator (or not ||)...
Which brings us back to the subject...
--
Alex Aulbach
On Fri, Aug 3, 2012 at 12:26 AM, Alex Aulbach alex.aulbach@gmail.comwrote:
2012/8/2 Andrew Faulds ajf@ajf.me:
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();Could be cool to make this in PHP with the 'or' operator (or not ||)...
Which brings us back to the subject...--
Alex Aulbach--
most/some of the ideas here were brought up before, there is a proposal and
a nice history of mailing list discussions (albeit not up-to-date) at
https://wiki.php.net/rfc/ifsetor
personally I would really like an ifsetor/coelesce kind of language
construct.
accepts any number of arguments, won't trigger notice on unset variables,
and returns the first non-null argument.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu