From 918d91eb9b807eb42bb50d644c27fe7f2ade8d7c Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 13 Oct 2021 10:52:56 -0600 Subject: [PATCH] Fix ReflectionParameter::isArray() was deprecated as of PHP 8.0.0 --- api/src/Etemplate/Widget.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/api/src/Etemplate/Widget.php b/api/src/Etemplate/Widget.php index 78941148e3..a3f41e0f23 100644 --- a/api/src/Etemplate/Widget.php +++ b/api/src/Etemplate/Widget.php @@ -553,12 +553,21 @@ class Widget $method = new ReflectionMethod($this, $method_name); foreach($method->getParameters() as $index => $param) { - if(!$param->isOptional() && !array_key_exists($index,$params)) + if(!$param->isOptional() && !array_key_exists($index, $params)) { error_log("Missing required parameter {$param->getPosition()}: {$param->getName()}"); $call = false; } - if($param->isArray() && !is_array($params[$index])) + // Check to see if method wants an array, and we're providing it + $paramType = $param->getType(); + if(!$paramType) + { + continue; + } + $types = $paramType instanceof \ReflectionUnionType + ? $paramType->getTypes() + : [$paramType]; + if(in_array('array', array_map(fn(\ReflectionNamedType $t) => $t->getName(), $types)) && !is_array($params[$index])) { error_log("$method_name expects an array for {$param->getPosition()}: {$param->getName()}"); $params[$index] = (array)$params[$index];