{"record":{"id":"e1848861c656a83a","repo":"PHPOffice/PhpSpreadsheet","slug":"value-e18488","errorCode":"#VALUE!","errorMessage":"#VALUE!","messagePattern":"#VALUE!","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Calculation\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php","lineNumber":116,"sourceCode":"     * @param mixed[] $myPoweredFactors\n     */\n    private static function processPoweredFactors(array &$allPoweredFactors, array &$myPoweredFactors): void\n    {\n        foreach ($myPoweredFactors as $myPoweredValue => $myPoweredFactor) {\n            if (isset($allPoweredFactors[$myPoweredValue])) {\n                if ($allPoweredFactors[$myPoweredValue] < $myPoweredFactor) {\n                    $allPoweredFactors[$myPoweredValue] = $myPoweredFactor;\n                }\n            } else {\n                $allPoweredFactors[$myPoweredValue] = $myPoweredFactor;\n            }\n        }\n    }\n\n    private static function testNonNulls(int $anyNonNulls): void\n    {\n        if (!$anyNonNulls) {\n            throw new Exception(ExcelError::VALUE());\n        }\n    }\n}\n","sourceCodeStart":98,"sourceCodeEnd":120,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php#L98-L120","documentation":"MathTrig\\Lcm::Lcm() walks its arguments, skips nulls, and only throws at the end via testNonNulls() with ExcelError::VALUE() when not a single non-null argument was found. This mirrors Excel's LCM(): with no usable numeric values the result is #VALUE!, not 0. Strings that fail numeric validation also surface as #VALUE!, but this specific throw means every argument was null.","triggerScenarios":"=LCM() over a range where all cells are empty, e.g. =LCM(A1:A3) with blanks; =LCM(\"\") or references that all resolve to null; calling Lcm::Lcm(null, null) directly from PHP.","commonSituations":"Ranges whose cells are only populated conditionally (report templates, optional columns) so LCM receives only blanks; formulas copied down a sheet where some rows have no data; wrappers that forward optional user input straight into LCM without defaults.","solutions":["Ensure at least one numeric argument reaches LCM; filter blanks before building the formula","Guard the formula: =IF(COUNT(A1:A3)=0, \"\", LCM(A1:A3))","Pass explicit numbers instead of relying on empty optional cells","Catch Calculation\\Exception if you invoke Lcm::Lcm() directly"],"exampleFix":"// before\n$sheet->getCell('B1')->setValue('=LCM(A1:A3)'); // all blank -> #VALUE!\n\n// after\n$sheet->getCell('B1')->setValue('=IF(COUNT(A1:A3)=0, 0, LCM(A1:A3))');","handlingStrategy":"validation","validationCode":"$args = array_values(array_filter($args, fn ($a) => $a !== null && is_numeric($a)));\nif ($args === []) {\n    return 0; // or '#VALUE!' policy result, instead of calling Lcm::Lcm()\n}\nreturn Lcm::Lcm(...$args);","typeGuard":"function hasAtLeastOneNonNull(array $args): bool\n{\n    return count(array_filter($args, fn ($a) => $a !== null)) > 0;\n}","tryCatchPattern":"try {\n    $lcm = \\PhpOffice\\PhpSpreadsheet\\Calculation\\MathTrig\\Lcm::Lcm(...$args);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Calculation\\Exception $e) {\n    $lcm = $e->getMessage(); // '#VALUE!'\n}","preventionTips":["Skip LCM when the input range has no numbers: =IF(COUNT(range)=0,\"\",LCM(range))","Do not forward optional/blank inputs into LCM; filter nulls first","Treat all-blank ranges as empty data, not as zero"],"tags":["phpspreadsheet","excel-formula","math","lcm","argument-validation","value-error"],"backgroundTag":"excel-value-error","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}