Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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);

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See