{"record":{"id":"8f18479c5bde1eab","repo":"PHPOffice/PhpSpreadsheet","slug":"formulae-with-more-than-two-array-arguments-are-no","errorCode":null,"errorMessage":"Formulae with more than two array arguments are not supported","messagePattern":"Formulae with more than two array arguments are not supported","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Calculation\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Calculation/Engine/ArrayArgumentHelper.php","lineNumber":37,"sourceCode":"    /** @var int[] */\n    protected array $columns;\n\n    /** @param mixed[] $arguments */\n    public function initialise(array $arguments): void\n    {\n        $keys = array_keys($arguments);\n        $this->indexStart = (int) array_shift($keys);\n        $this->rows = $this->rows($arguments);\n        $this->columns = $this->columns($arguments);\n\n        $this->argumentCount = count($arguments);\n        $this->arguments = $this->flattenSingleCellArrays($arguments, $this->rows, $this->columns);\n\n        $this->rows = $this->rows($arguments);\n        $this->columns = $this->columns($arguments);\n\n        if ($this->arrayArguments() > 2) {\n            throw new Exception('Formulae with more than two array arguments are not supported');\n        }\n    }\n\n    /** @return mixed[] */\n    public function arguments(): array\n    {\n        return $this->arguments;\n    }\n\n    public function hasArrayArgument(): bool\n    {\n        return $this->arrayArguments() > 0;\n    }\n\n    public function getFirstArrayArgumentNumber(): int\n    {\n        $rowArrays = $this->filterArray($this->rows);\n        $columnArrays = $this->filterArray($this->columns);","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Calculation/Engine/ArrayArgumentHelper.php#L19-L55","documentation":"PhpSpreadsheet's array-argument engine handles at most two array (multi-cell) arguments per function call. ArrayArgumentHelper::initialize() counts arguments whose rows>1 or columns>1 after flattening single-cell arrays, and throws this exception as soon as a third array argument appears, instead of evaluating the formula. It is a deliberate engine limitation, not an input-formatting mistake.","triggerScenarios":"Array formulas like =SUM(A1:A3*B1:B3*C1:C3) where three ranges feed one operation; expressions like =ROUND(A1:A3+B1:B3*C1:C3, D1:D3); calling any ArrayEnabled calculation function directly with three array parameters (it routes through evaluateArrayArguments -> ArrayArgumentProcessor -> this check).","commonSituations":"Porting Excel workbooks that rely on legacy CSE array formulas or dynamic arrays with three-plus ranges; array-heavy financial models; upgrading from PHPExcel-era code where such formulas degraded to scalar behaviour instead of throwing.","solutions":["Rewrite the formula to use at most two array arguments per operation - e.g. =SUMPRODUCT(A1:A3*B1:B3*C1:C3) (SUMPRODUCT natively takes multiple ranges) or nest/chunk the multiplication.","Split the computation into intermediate helper columns/cells and aggregate the scalars afterwards.","When importing untrusted workbooks, wrap calculation in try/catch on PhpOffice\\PhpSpreadsheet\\Calculation\\Exception and report the offending cell for manual rework.","Pre-scan formula strings for three or more range operands (A1:B2 patterns) before calculating to flag risky cells."],"exampleFix":"// before - throws 'Formulae with more than two array arguments are not supported'\n$sheet->getCell('E1')->setValue('=SUM(A1:A3*B1:B3*C1:C3)');\n\n// after - SUMPRODUCT accepts any number of arrays\n$sheet->getCell('E1')->setValue('=SUMPRODUCT(A1:A3*B1:B3*C1:C3)');","handlingStrategy":"try-catch","validationCode":"// Cheap pre-flight when importing formulas: flag cells whose formula shows\n// three or more range operands in one expression.\nfunction hasTooManyArrayOperands(string $formula): bool\n{\n    preg_match_all('/[A-Za-z]+!?\\$?[A-Z]{1,3}\\$?\\d+:\\$?[A-Z]{1,3}\\$?\\d+/', $formula, $m);\n    return count(array_unique($m[0])) > 2;\n}","typeGuard":null,"tryCatchPattern":"use PhpOffice\\PhpSpreadsheet\\Calculation\\Exception as CalcException;\n\ntry {\n    $value = $cell->calculate(); // evaluates the cell's formula\n} catch (CalcException $e) {\n    // 'Formulae with more than two array arguments are not supported'\n    $logger->warning('Unsupported array formula at ' . $cell->getCoordinate() . ': ' . $e->getMessage());\n    $value = null;\n}","preventionTips":["Rewrite three-range array math as SUMPRODUCT, which accepts any number of array arguments.","Split complex array formulas into helper columns and aggregate the scalars.","Audit imported workbooks for CSE/dynamic-array formulas before running bulk calculation.","Keep the try/catch around batch calculation so one bad cell does not abort the whole run."],"tags":["phpspreadsheet","array-formula","calculation-engine","formula-limit","cse-formula"],"backgroundTag":"array-formula-limit","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}