Hi Rowan, That's a really interesting idea, and I completely agree with you.
A lazy array slice type would be a big step forward for PHP. It could open the door to a lot of more composable and memory-friendly APIs. I think it's a bigger topic than this RFC, so I'd love to explore it properly in a separate proposal. For now, I'll keep array_search_range() focused on its simple use case, and I'm happy to help shape the lazy slice idea when the time comes. Thanks for the thoughtful feedback! Sepehr On پنجشنبه ۱۳ اوت ۲۰۲۶، ۱۹:۰۸ Rowan Tommins [IMSoP] <[email protected]> wrote: > On 12 August 2026 23:56:55 BST, Morgan <[email protected]> wrote: > >On 2026-08-13 02:27, سپهر محمودی wrote: > >> Hi everyone, > >> > >> The main motivation is to provide a memory-efficient way to search > within a specific range of an array, avoiding the overhead of creating > intermediate arrays with array_slice(). > >> > >Have you thought about expanding this idea to include other functions > with similar jobs (e.g. array_find, array_find_key, array_all, array_any)? > > > I think it would be better to design something more composable - that is, > a way to create a "lazy array slice", and then accept that in functions > which can use it safely. > > Swift, for instance, has both ArraySlice and Substring types which let you > refer to a subset of an array or string without copying any data: < > https://developer.apple.com/documentation/swift/arrayslice> < > https://developer.apple.com/documentation/swift/substring> > > It's conceptually similar to using an Iterator instead of filling an array > with a range of values. > > Regards, > > Rowan Tommins > [IMSoP] >
