Skip to content

Commit f8d994b

Browse files
committed
POWER Needs to Accept NULL Args
Investigating issue #1622, I found that its extremely complicated formula, which had been leading to an incorrect result, now led to an exception. I am able to fix the exception; unfortunately, I am no closer to resolving the original issue. So I'll apply the baby step while continuing to investigate. Function POWER had changed from untyped args to a defined set of types. The set of types was determined according to the doc block, but that was incomplete - it had neglected to include `null` and `bool`. This PR corrects the function prototype and the doc block, and adds the missing tests for those conditions.
1 parent 563de5f commit f8d994b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/PhpSpreadsheet/Calculation/MathTrig/Operations.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public static function mod(mixed $dividend, mixed $divisor): array|string|float
5252
*
5353
* Computes x raised to the power y.
5454
*
55-
* @param array|float|int|string $x Or can be an array of values
56-
* @param array|float|int|string $y Or can be an array of values
55+
* @param null|array|bool|float|int|string $x Or can be an array of values
56+
* @param null|array|bool|float|int|string $y Or can be an array of values
5757
*
5858
* @return array|float|int|string The result, or a string containing an error
5959
* If an array of numbers is passed as an argument, then the returned result will also be an array
6060
* with the same dimensions
6161
*/
62-
public static function power(array|float|int|string $x, array|float|int|string $y): array|float|int|string
62+
public static function power(null|array|bool|float|int|string $x, null|array|bool|float|int|string $y): array|float|int|string
6363
{
6464
if (is_array($x) || is_array($y)) {
6565
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $y);

tests/data/Calculation/MathTrig/POWER.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,9 @@
410410
],
411411
['#VALUE!', 'x', 2],
412412
['#VALUE!', 2, 'x'],
413+
'exponent is null' => [1, 2, null],
414+
'base is null' => [0, null, 2],
415+
'both null' => ['#NUM!', null, null],
416+
'exponent is bool' => [2, 2, true],
417+
'base is bool' => [0, false, 2],
413418
];

0 commit comments

Comments
 (0)