Can’t use function return value in write context
Description
A write context is any position that needs an actual variable slot to write to, remove, or bind a reference to: the left side of an assignment, the target of unset(), a foreach-by-reference variable, and similar. A function call only produces a value; it does not designate a storage location, so the engine has nothing to write to, unset, or reference, and rejects the call outright at compile time, before it is ever executed.
Example
<?php
function getValue() {
return 5;
}
getValue() = 3;
unset(getValue());
?>
Alternatives
- Store the return value in a variable first, then use the variable in the write context: $v = getValue(); unset($v);
Related error messages
- can’t-use-method-return-value-in-write-context
- cannot-use-result-of-built-in-function-in-write-context
- can’t-use-nullsafe-operator-in-write-context
- cannot-use-temporary-expression-in-write-context
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See