PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception

Invalid Operation for Blanks CF Rule Wizard

Error message

Invalid Operation for Blanks CF Rule Wizard

What it means

The Blanks wizard exposes its operators through __call: every invocation is checked against a fixed OPERATORS map whose only keys are 'isBlank', 'empty', 'notBlank' and 'notEmpty'. Any other method name throws. Note the trap: the class docblock advertises isEmpty(), but the runtime map contains 'empty', so ->isEmpty() throws while ->empty() and ->isBlank() work.

Source

Thrown at src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Blanks.php:88

        ) {
            throw new Exception('Conditional is not a Blanks CF Rule conditional');
        }

        $wizard = new self($cellRange);
        $wizard->style = $conditional->getStyle();
        $wizard->stopIfTrue = $conditional->getStopIfTrue();
        $wizard->inverse = $conditional->getConditionType() === Conditional::CONDITION_CONTAINSBLANKS;

        return $wizard;
    }

    /**
     * @param mixed[] $arguments
     */
    public function __call(string $methodName, array $arguments): self
    {
        if (!array_key_exists($methodName, self::OPERATORS)) {
            throw new Exception('Invalid Operation for Blanks CF Rule Wizard');
        }

        $this->inverse(self::OPERATORS[$methodName]);

        return $this;
    }
}

View on GitHub (pinned to 65b080eef4)

Solutions

  1. Use only isBlank(), empty(), notBlank(), notEmpty()
  2. Prefer isBlank()/notBlank() - they are unambiguous and match the other wizards' style
  3. Validate dynamically chosen method names against the allowed list before invoking
  4. Catch PhpSpreadsheetException around dynamic calls to fail softly

Example fix

// before
$blanksWizard = (new Wizard('A1:E10'))->newRule(Wizard::BLANKS);
$blanksWizard->isEmpty();   // throws: runtime operator key is 'empty', not 'isEmpty'

// after
$blanksWizard->isBlank();   // or ->empty(), ->notBlank(), ->notEmpty()
Defensive patterns

Strategy: validation

Validate before calling

$allowed = ['isBlank', 'empty', 'notBlank', 'notEmpty'];
$method = $config['blankOperator'] ?? 'isBlank';
if (!in_array($method, $allowed, true)) {
    throw new InvalidArgumentException('Unknown Blanks operator: ' . $method);
}
$wizard->$method();

Try / catch

use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;

try {
    $wizard->$method();
} catch (PhpSpreadsheetException $e) {
    // $method is not one of isBlank/empty/notBlank/notEmpty
    throw new InvalidArgumentException('Invalid blank operator: ' . $method, 0, $e);
}

Prevention

When it happens

Trigger: Calling ->isEmpty() (the docblock name that has no runtime key); case-mismatched names like ->notblank() or ->IsBlank(); guessed names such as ->isNotEmpty() or ->blank().

Common situations: IDE autocompletion picking the docblock's isEmpty(); developers assuming symmetric naming with other wizards; fluent chains built dynamically from user-supplied operator names.

Related errors


AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17). Data as JSON: /api/errors/f7472951dde73e4a. Report an issue: GitHub.