{"record":{"id":"9be5a6b3fba77086","repo":"PHPOffice/PhpSpreadsheet","slug":"value-9be5a6","errorCode":"#VALUE!","errorMessage":"#VALUE!","messagePattern":"#VALUE!","errorType":"error_code","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Calculation/Engineering/BitWise.php","lineNumber":213,"sourceCode":"     */\n    private static function validateBitwiseArgument(mixed $value): float\n    {\n        $value = self::nullFalseTrueToNumber($value);\n\n        if (is_numeric($value)) {\n            $value = (float) $value;\n            if ($value == floor($value)) {\n                if (($value > 2 ** 48 - 1) || ($value < 0)) {\n                    throw new Exception(ExcelError::NAN());\n                }\n\n                return floor($value);\n            }\n\n            throw new Exception(ExcelError::NAN());\n        }\n\n        throw new Exception(ExcelError::VALUE());\n    }\n\n    /**\n     * Validate arguments passed to the bitwise functions.\n     */\n    private static function validateShiftAmount(mixed $value): int\n    {\n        $value = self::nullFalseTrueToNumber($value);\n\n        if (is_numeric($value)) {\n            if (abs($value + 0) > 53) {\n                throw new Exception(ExcelError::NAN());\n            }\n\n            return (int) $value;\n        }\n\n        throw new Exception(ExcelError::VALUE());","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Calculation/Engineering/BitWise.php#L195-L231","documentation":"#VALUE! from the bitwise argument validator when the value is not numeric at all (after null/bool have been coerced to numbers). validateBitwiseArgument() falls through to throw Calculation\\Exception('#VALUE!') for strings like 'abc', objects, resources, etc.; BITAND/BITOR/BITXOR/BITLSHIFT/BITRSHIFT return it as the '#VALUE!' result string.","triggerScenarios":"=BITAND(\"x\", 1); BitWise::BITOR('hello', 2); a cell containing text used as a bitwise operand; null and true/false are accepted (0/1) but any other non-numeric type or string fails.","commonSituations":"Referencing text cells or headers in bitwise formulas; unvalidated string input from forms/APIs; Excel files where a column has mixed types.","solutions":["Coerce or verify operands are numeric before calling (is_numeric() on the scalar, or Cell::getValue() + datatype check when reading cells).","Reject or clean non-numeric input at the API boundary instead of relying on the formula to fail.","Check returned values for '#VALUE!' when operands come from users."],"exampleFix":"// before\n$result = BitWise::BITAND($cellValue, 0xFF); // $cellValue = 'N/A' -> '#VALUE!'\n\n// after\n$result = is_numeric($cellValue)\n    ? BitWise::BITAND((int) $cellValue, 0xFF)\n    : 0; // or throw your own domain exception","handlingStrategy":"type-guard","validationCode":"if (!is_numeric($operand)) {\n    throw new \\InvalidArgumentException('bitwise operand must be numeric, got ' . gettype($operand));\n}\n$result = BitWise::BITAND((int) $operand, 0xFF);","typeGuard":"/** Bitwise operands must be numeric (null/bool are coerced to 0/1 by the engine). */\nfunction isCoercibleBitwiseValue(mixed $v): bool\n{\n    return $v === null || is_bool($v) || is_numeric($v);\n}","tryCatchPattern":null,"preventionTips":["Check cell data types before using them as bitwise operands.","Filter placeholder strings ('N/A', '-') out of numeric columns on import.","Remember only null/bool get automatic coercion; every other non-numeric value fails."],"tags":["phpspreadsheet","excel-formula","bitwise","type-error","non-numeric-input"],"backgroundTag":"excel-value-error","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}