Bug #78440 [Opn->Fbk]: Array-callables wont work if class has only __call/__callStatic

From: Date: Wed, 21 Aug 2019 16:45:22 +0000
Subject: Bug #78440 [Opn->Fbk]: Array-callables wont work if class has only __call/__callStatic
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222352@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78440&edit=1 ID: 78440 Updated by: requinix@php.net Reported by: 6562680 at gmail dot com Summary: Array-callables wont work if class has only __call/__callStatic -Status: Open +Status: Feedback Type: Bug Package: Reflection related Operating System: Win10 PHP Version: 7.2.21 Block user comment: N Private report: N New Comment: Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. Previous Comments: ------------------------------------------------------------------------ [2019-08-21 16:40:04] 6562680 at gmail dot com Description: ------------ I know about 7.4 and array-functions, seems like good solution. So, currently i found 2 problems with Reflection 1. When you passing callable as string or array, you should be sure that passed arguments count will be EXACTLY match await arguments count. Maybe as solution, but \Closure::class works well. If you pass too many arguments, it just ignored. Because of that i should write bind() function that creates closure from these callable, controls bound arguments with \ReflectionClass 2. When i have few libraries with functions, sometimes i want call function that will be declared only when first access (because library has a constructor) by passing array inside mapper, filter or reducer. So i cant do this because library has another module inside (that works only with dependency injector) - so trying to pass array with that [ ProxyLib::class, 'func' ] expectedly ends with "method not found exception". Of course - if i use \Closure for that - it works well because of dynamic loading. Test script: --------------- /* * 1st */ array_reduce($array, 'is_array', []); // nvm, just an example // throws Too many arguments /* * 2nd */ Class Proxy { public static function __callStatic($method, $arguments) { // yes we should use DI or something here return (new Dynamic)->{ $method }(...$arguments); } } Class Dynamic { public function __construct() { $this->loadSomeDataOnInit(); } public function reducer($carry, $item) { return $carry; } } array_reduce($array, [ Proxy::class, 'reducer' ], []); // throws Method not found array_reduce($array, function ($carry, $item) { return Proxy::reducer($carry, $item); // works well, because of dynamic loading }, []); Expected result: ---------------- 1st: ignore if too many, exception if not enough 2st: auto-wrap into closure ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78440&edit=1

« previous php.bugs (#222352) next »