diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index 34062a531..960db939c 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -5072,7 +5072,7 @@ class Calculation krsort($args); krsort($emptyArguments); - if ($argCount > 0) { + if ($argCount > 0 && is_array($functionCall)) { $args = $this->addDefaultArgumentValues($functionCall, $args, $emptyArguments); } @@ -5571,7 +5571,7 @@ class Calculation private function addDefaultArgumentValues(array $functionCall, array $args, array $emptyArguments): array { - $reflector = new ReflectionMethod(implode('::', $functionCall)); + $reflector = new ReflectionMethod($functionCall[0], $functionCall[1]); $methodArguments = $reflector->getParameters(); if (count($methodArguments) > 0) { diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PiTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PiTest.php new file mode 100644 index 000000000..130f02f98 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PiTest.php @@ -0,0 +1,32 @@ +mightHaveException($expectedResult); + $sheet = $this->getSheet(); + if ($number !== null) { + $sheet->getCell('A1')->setValue($number); + } + if ($number === 'omitted') { + $sheet->getCell('B1')->setValue('=PI()'); + } else { + $sheet->getCell('B1')->setValue('=PI(A1)'); + } + $result = $sheet->getCell('B1')->getCalculatedValue(); + self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + } + + public static function providerPI(): array + { + return require 'tests/data/Calculation/MathTrig/PI.php'; + } +} diff --git a/tests/data/Calculation/MathTrig/PI.php b/tests/data/Calculation/MathTrig/PI.php new file mode 100644 index 000000000..317cd1786 --- /dev/null +++ b/tests/data/Calculation/MathTrig/PI.php @@ -0,0 +1,8 @@ + ['exception', 1], +];