Reputation: 4783
The null coalescing operator (??
) returns its first operand if it exists and is not NULL, and otherwise returns its second operand.
If the first operand is a function or method call, does the operator call the function call twice?
As an example, say the function get_name()
returns a string value or null.
$name = get_name() ?? 'no name found';
So is get_name()
called once and the value stored ready to assign it to the variable ($name
) or when the ??
is activated due to the function returning a value that is true for isset()
, does ??
call on the first operand a second time to get the value?
Upvotes: 3
Views: 831