Skip to content

Commit f2e190e

Browse files
Replace "use-by-ref" by static vars when possible in closures
1 parent 0120462 commit f2e190e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

AbstractUnicodeString.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ public function ascii(array $rules = []): self
155155
public function camel(): static
156156
{
157157
$str = clone $this;
158-
$str->string = str_replace(' ', '', preg_replace_callback('/\b.(?![A-Z]{2,})/u', static function ($m) use (&$i) {
158+
$str->string = str_replace(' ', '', preg_replace_callback('/\b.(?![A-Z]{2,})/u', static function ($m) {
159+
static $i = 0;
160+
159161
return 1 === ++$i ? ('İ' === $m[0] ? '' : mb_strtolower($m[0], 'UTF-8')) : mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8');
160162
}, preg_replace('/[^\pL0-9]++/u', ' ', $this->string)));
161163

LazyString.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public static function fromCallable(callable|array $callback, mixed ...$argument
3030
}
3131

3232
$lazyString = new static();
33-
$lazyString->value = static function () use (&$callback, &$arguments, &$value): string {
33+
$lazyString->value = static function () use (&$callback, &$arguments): string {
34+
static $value;
35+
3436
if (null !== $arguments) {
3537
if (!\is_callable($callback)) {
3638
$callback[0] = $callback[0]();

0 commit comments

Comments
 (0)