[Variadic] Specifying the list shape for variadic handler implementations #15074
|
Currently, for variadic syntax it is possible to define the type or a shape of individual element, which is typical case and well-supported, however in some cases, variadic arguments are typed individually, representing the concrete list shape. I'm looking for a solution to define the exact list shape for such variadic functions/methods. See an example from playground: https://phpstan.org/r/a9cc25b5-dc7f-47f9-9718-53e62fda6e61 |
Replies: 2 comments 2 replies
|
Hi, I've been thinking about this and I think the OOP design of HookInterface / concrete hook doesn't work well. There's no value to HookInterface::handle. You're typing Presumably you have Personaly I'd get rid of HookInterface and type the handle methods normally, with three to four native parameters. |
|
The problem here, that I can not dictate the Hook interface, it is dictated by the Zend Engine and how it emulates the callback via FFI trampoline, each callback is just a thin wrapper, which usually do CData <=> Native PHP value tricks behind like this https://github.com/lisachenko/z-engine/blob/8.4/src/ClassExtension/Hook/DoOperationHook.php#L79-L107 - this will give PHP developers normal variable and not internal C structures. To hide the complexity of Zend Engine internals, I decided to declare all handlers defined as variadic and each concrete handler takes the CData, effectively I can put I understand why you proposing to drop the interface, but it is hard to do it without automation of low-level mappings. Thus all these games around object/list shapes... Anyway, thank you for the feedback, you confirmed that there is no easy way to declare it now. At least I know this fact now ) |
Currently it's not, PHPStan will check each variadic argument against the same type. You can't declare any difference either, it'd need a new syntax, maybe a new PHPDoc tag.
But you can open a feature request to track this in the future 😊