Skip to content
loading...

re: Best Practice - Check if property exist and assign VIEW POST

TOP OF THREAD FULL DISCUSSION
re: One way to make this shorter is to use PHP7's null coalesce operator: $i->samples = $issues['samples'] ?? null; and to make it a bit DRYe...
 

PHP7's null coalesce operator is awesome, thank you for pointing this out.
I like the other options more for the purpose of my question but this is a great "upgrade" from the inline if.

I do like Alex Cioroianu suggestion as I don't really need to assign a value if it does not exist but this is still helpful if I need to assign some fallback value or similar.

Cheers

code of conduct - report abuse