3 ms·
> 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"?
by stephenr 9y ago
> 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"?
- bpicolo 9y agoWith all notices on accessing an undefined index is a notice, which you're doing with that syntax, no?
- CiPHPerCoder 9y agoNope. https://3v4l.org/J45qU https://3v4l.org/J45qU
- bpicolo 9y agoAhh this is new in 7.0. Good to know, hadn't seen that. Still of the opinion that the array builtins are a hassle. =]
- deleted 9y ago[deleted]
- aruggirello 9y agoNo 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...