What is null coalescing assignment ??= operator in PHP 7.4

后端 未结 5 1634
渐次进展
渐次进展 2020-12-06 16:51

I\'ve just seen a video about upcoming PHP 7.4 features and saw this new ??= operator. I already know the ?? operator.

How\'s this different

5条回答
  •  难免孤独
    2020-12-06 17:21

    The null coalescing assignment operator is a shorthand way of assigning the result of the null coalescing operator.

    An example from the official release notes:

    $array['key'] ??= computeDefault();
    // is roughly equivalent to
    if (!isset($array['key'])) {
        $array['key'] = computeDefault();
    }
    

提交回复
热议问题