Skip to content

Commit 244eb2c

Browse files
minor #49763 Replace "use-by-ref" by static vars when possible in closures (nicolas-grekas)
This PR was merged into the 6.3 branch. Discussion ---------- Replace "use-by-ref" by static vars when possible in closures | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Might be easier to grasp. Commits ------- 65422ecf4b Replace "use-by-ref" by static vars when possible in closures
2 parents d5249b0 + 6c116e6 commit 244eb2c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Question/Question.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ public function setAutocompleterValues(?iterable $values): static
148148

149149
$callback = static fn () => $values;
150150
} elseif ($values instanceof \Traversable) {
151-
$valueCache = null;
152-
$callback = static function () use ($values, &$valueCache) {
151+
$callback = static function () use ($values) {
152+
static $valueCache;
153+
153154
return $valueCache ??= iterator_to_array($values, false);
154155
};
155156
} else {

0 commit comments

Comments
 (0)