Hello Internals, I want to request making possible to catch functions with wrong signature when passed as callable. In other words, when a function or a method is passed as callable value, PHP will first confirm whether the function is of the write callable type that the function being executed requires. It will help catch silent errors. Currently, PHP does following: 1. Confirms whether a callable is valid. 2. Passes the callable value to a function, and the execution starts. 3. If the passed function receives values which's type is different than function signature, PHP throws an error. 4. If passed function returns nothing, the variable that wanted a value from the passed function receives null. 5. As a result, the unexpected results emerge. To resolve this issue, I propose to introduce a mechanism that allows to hint callable signatures. To understand the spirit of this request, look at the similar functionality that Angel Script Project provides with. 1. One defines a function definition. 2. Use its name to hint the same signature. 3. The compiler alerts about the incorrect signature before passing this to a function. If I could do this in PHP, I would write like following: `funcdef preg_replace_callback_hint(array $matches) : string;` If I accidently pass a callable which's signature is different than desired function call, the error is caught earlier. This message does not suggests syntax; it only points to a problem and suggests a solution. Any volunteers that would love to come up with syntax and implement this? I am curious to see the feedback. Regards Hamza Ahmad
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php