do_something(@$_GET['foobar']);
There are ways to suppress PHP notices without just turning off the E_NOTICE output. do_something(@$_GET['foobar']);
There are ways to suppress PHP notices without just turning off the E_NOTICE output.It's also making the interpreter do unnecessary error handling work when a simple "if ($_GET['foobar'])" would suffice.
$one->{ two }->{ three } = [ $four ]
Without having to check every link for definedness makes for cleaner code, IMO. Making it optional "suppressing that error" would be a good middle-ground.Coffeescipt has the existential operator, not quite on a par with Perl's autovivification, which allows:
zip = lottery.drawWinner?().address?.zipcodeInstead, I use a 'get or else' function, as in some functional languages. For arrays, it goes
function get_or_else($array,$key,$default=null)
{ return isset($array[$key]) ? $array[$key] : $default; }
This avoids any warnings, and also allows you to specify a default.Your solution makes for some good boilerplate, but things like that are exactly why I use Python for everything it makes sense for: these things are baked into the language (in Python it would be array.get(key, default) ).
I'd rather be using Python too, but for some apps we have to work with a lot of PHP legacy code, so I do what I can.
Scala borrows the option types from SML (or, at least, SML has them and is much older). I love SML for its strict semantics (if something passes through the type system it most likely works as expected), but sadly design really doesn't inform platform choice (case in point: C++ is still common. I don't hate it as much as some people do, but it can't be said to be particularly well designed).