Tag Archives: PHP 7

PHP 7.4 – Null Coalesce Assignment Operator

PHP 7.4 added a new Null Coalesce Assignment Operator (??=) which is an enhancement of Null Coalesce Operator (??) introduced in PHP 7. The Null Coalesce Assignment Operator (??=) assigns the value of the right-hand parameter if the left-hand parameter is null. If the left-hand parameter is not null then its value is not changed. The Null Coalesce Assignment Operator is sometimes also called as Null Coalesce Equal Operator.
Read more »

PHP 7 – Combined Comparison (Spaceship) Operator

In this post we will take a look and another new operator in PHP 7. This operator is the Combined Comparison or Spaceship operator (<=>). This operator is a three way comparison operator. It will do greater-than, less-than and equal comparisons between two operands.

The spaceship operator (<=>) returns -1 if the left side is smaller, 0 if the values are equal and 1 if the left side is larger. It can be used on all generic PHP values with the same semantics as < , <=, ==, >=, >. This operator is similar in behavior to strcmp() or version_compare(). This operator can be used with integers, floats, strings, arrays, objects, etc.
Read more »

PHP 7 – Null Coalesce Operator

PHP 7 brings a lot of improvements, features and new operators as compared to the earlier versions on PHP. One of the new operators is the Null Coalesce Operator (??). This operator can be used instead of using isset() along with the ternary operator (?:).

The Null coalesce operator (??) returns the result of its first operand if it exists and is not NULL, or else it will return its second operand. Using this operator like $_GET[‘mykey’] ?? “” will not raise an E_NOTICE, and can be safely used.
Read more »