Re: Array spread append
| From: | Hans Krentel via internals | Date: | Sun, 09 Apr 2023 18:28:24 +0000 |
| Subject: | Re: Array spread append | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119841@lists.php.net to get a copy of this message | ||
On Saturday 08 April 2023 22:17:14 (+02:00), Niels Dossche wrote:
However, I think it might be worth adding an optimization for the most common $x = array_merge($x, ...) case.If so, then syntax wise I'd throw that suggestion in the ring: $x[] = ... $y ; This would allow to adopt existing code (from push one to splat from iterable); is short; the splat operator in front of where I'd expect it and the existing semantic of $x[] "append operator" (a.k.a. "push"). Not the idea for multiple operands thought, this might be a bigger upgrade: $x[] = ... $y , $y[0], ... $z ; as it would also require to work without the splat operator for reasonable symmetry: unset($x); $x[] = 1; $x[] = 2, 3; $x[] = ... range(4, 6), 7; Semantics still look clear to me, but I can't write an implementation. And optimization wise ArrayAccess could benefit from a specialization form then, e.g. ::offsetPush($offset, iteratable $values) which should be optional, or perhaps even with offsetSet($offset, mixed ...$values) as an optional upgrade if PHP semantics allow such changes. Just my 2 cents. -- hakre