Factories::models breaks __callStatic function arguments passed to the class |
Hey everyone just a quick note that within framework/system/Config/Factories.php there's public static function models that calls __callStatic where new $class (...$arguments) is called and the only option for $arguments is to be object ConnectionInterface or null yet only arrays and Traversables can be unpacked.
Screenshot: ![]() I have many projects relying on this feature that pass real array of arguments into model constructors yet now the only way is to pass ConnectionInterface object. This issue is not critical on my end i already worked around it by using __callStatic directly, thank god it's a public function.
What do you mean?
It seems Model constructor accept only ConnectionInterface and ValidationInterface. https://github.com/codeigniter4/CodeIgni...l.php#L132
I don't understand?
After array shifting $name and $options from the $arguments array, what remains is the ConnectionInterface object wrapped in an array. So unpacking will still work. See https://3v4l.org/NCRCC
I used to call my models trough CI Factory -> Models which previously allowed me to pass custom arguments, here's what my typical CI model looks (stripped comments for this thread):
PHP Code: class Envelope extends Core Previously i could call model(options, arguments) and extract $arguments into new model constructor. PHP Code: Factories::model($name, ['instanceOf' => $path, 'preferApp' => false, 'getShared' => false], $arguments) But now in updated code that i mentioned in creation of this thread this cannot work anymore. Alright, no big deal. Just try not to create constraints for developers ![]()
Factories::model() is a workaround. If anyone knows the solution, please send a PR.
Quote: * This method is only to prevent PHPStan error. |
Welcome Guest, Not a member yet? Register Sign In |