> get_default($array, $key, $default).
$array[$key] ?? $default
im still not sure what any of this has to do with "the only secure php is no php"?
With all notices on accessing an undefined index is a notice, which you're doing with that syntax, no?
Re:Simply Secure PHP Cryptography
by aruggirello on Thursday July 13, 2017 @03:47PM
(#14764544)
No notices - But this syntax has been introduced in 7.0.
Old style is:
isset($array[$key]) ? $array[$key] : $default
Which is, admittedly, just a bit uglier.
Edit: isset() is a language construct, not a function call. So it does not incur performance penalties. The ?? operator was introduced for 'cosmetic' reasons only, so don't rush to update your source...
Re:Simply Secure PHP Cryptography
by CiPHPerCoder on Thursday July 13, 2017 @02:50PM
(#14764033)
Nope. https://3v4l.org/J45qU
$foo = 1; $foo[1]; // no problems
$foo = true; $foo[0]; // seems good to php
PHP's choose-your-own-error-adventure with all errors on (which is the only good choice) is pretty silly. arrays become somewhat unwieldy because the core libs for arrays are deficient, missing things like a get_default($array, $key, $default).
The array core lib in general is troublesome to understand/intuit different pieces for, probably because mashing hash types and lists together leads to all sorts of ambiguity (like ambiguous json decoding/encoding). Want some subset of an array? Sure, that's the super-intuitive `array_intersect_key($array, array_flip($keys));`
The core array type is really a frustrating experience in PHP, and interop deficiencies with ArrayObject make it unusable as an alternative.