On Tue, May 11, 2021, at 1:32 PM, Nicolas Grekas wrote: > > > BTW, ideally, partial functions should not increase the depth of the > > > stacktrace at all. Do they? > > > > > > Nicolas > > > > They currently do, since they work by creating a Closure-esque object > > called Partial with an __invoke() method. However, if you partial the same > > thing multiple times then only one stack level gets added. > > > > Nice. Would it be possible to optimize this and remove the extra frame? At > least maybe for the (?) case?
I'd have to defer to Joe (he wrote the implementation), but I suspect not. The partial has to be there to carry around the information of what callable to actually call and what the bound parameters are. At that point, it's likely more work to decompose the Partial internally before calling it than to just call the Partial itself. > This makes me wonder: can we create a partial programmatically? Wouldn't > that be needed for some use cases? > Partial::createFromCallable($callable, the-args)? > > Nicolas I cannot think of a use case where that would be needed. Since you can partial-ize any callable, including a dynamic one, if you needed to do something like partial-ize one of a series of function calls you can do that already: $c = match($some_input) { 'A' => 'func_a', 'B' => 'func_b', 'C' => 'func_c', }; $p = $c(1, 2 ?, 4); Though at that point, just partialing them in the first place inside the match would be better as then you never have a function name in a string to begin with. --Larry Garfield -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php