Cannot use variable $%pS twice
Description
The use clause of a closure lists the variables imported from the enclosing scope. Each variable can only appear once in that list: importing the same variable twice, whether by value or by reference, is redundant and not allowed.
This is checked at compile time, as the use list is processed.
Example
<?php
function foo() {
$a = 1;
return function () use ($a, $a) {
return $a;
};
}
?>
Literal Examples
- Cannot use variable $a twice
Alternatives
- Remove the duplicate entry in the
useclause.
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See