0

I am using PHPStorm and the inspection is recommending that I switch this line of code:

$orderings['custom'][$child->id] = isset($custom_values[$child->id]) ? $custom_values[$child->id] : $next_order++;

to this:

$orderings['custom'][$child->id] = $custom_values[$child->id] ?? $next_order++;

But I can't find information in the PHP documentation about this change. Are changes like this non breaking and what is the ?? doing?

  • It's PHP's [null coalescing operator](https://stackoverflow.com/questions/53610622/what-does-double-question-mark-operator-mean-in-php) – 0stone0 May 13 '20 at 13:35
  • 1
    See the [documentation](https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op). Do note that `??` will produce a syntax error on any setup with ` – DarkBee May 13 '20 at 13:35
  • @DarkBee that explains what this does. Thank you. :) –  May 13 '20 at 13:41

1 Answers1

0

In this statement...

$orderings['custom'][$child->id] = $custom_values[$child->id] ?? $next_order++;

?? it work as

  • if $custom_values[$child->id] value is not null then it use $custom_values[$child->id] value
  • if $custom_values[$child->id] value is null then it use $next_order value
Ashish Sondagar
  • 917
  • 1
  • 9
  • 16