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

From: Date: Wed, 21 Aug 2019 16:40:04 +0000
Subject: Bug #78440 [NEW]: Array-callables wont work if class has only __call/__callStatic
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222351@lists.php.net to get a copy of this message
From: 6562680 at gmail dot com Operating system: Win10 PHP version: 7.2.21 Package: Reflection related Bug Type: Bug Bug description:Array-callables wont work if class has only __call/__callStatic 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 bug report at https://bugs.php.net/bug.php?id=78440&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=78440&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=78440&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=78440&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=78440&r=needscript Try newer version: https://bugs.php.net/fix.php?id=78440&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=78440&r=support Expected behavior: https://bugs.php.net/fix.php?id=78440&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=78440&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=78440&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=78440&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=78440&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=78440&r=dst IIS Stability: https://bugs.php.net/fix.php?id=78440&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=78440&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=78440&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=78440&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=78440&r=mysqlcfg

« previous php.bugs (#222351) next »