PHPOffice/PHPWord · error · InvalidArgumentException

Invalid value, dirty or clean possible

Error message

Invalid value, dirty or clean possible

What it means

ProofState::setSpelling() only accepts the class constants CLEAN or DIRTY (compared loosely with ==). Any other value throws an InvalidArgumentException with the message 'Invalid value, dirty or clean possible'. It mirrors the OOXML proofState spelling attribute, which may only be 'clean' or 'dirty'.

Solutions

  1. Pass ProofState::CLEAN or ProofState::DIRTY constants exactly
  2. Map your boolean/state value to the constants before calling: $state ? ProofState::DIRTY : ProofState::CLEAN
  3. Validate input with in_array($value, [ProofState::CLEAN, ProofState::DIRTY]) before the call

Example fix

// before
$proofState->setSpelling(true);
// after
$proofState->setSpelling(ProofState::DIRTY);
Defensive patterns

Strategy: validation

Validate before calling

if ($spelling !== ProofState::CLEAN && $spelling !== ProofState::DIRTY) {
    throw new UnexpectedValueException('spelling must be ProofState::CLEAN or ProofState::DIRTY');
}

Type guard

function isValidProofState(?string $v): bool {
    return $v === ProofState::CLEAN || $v === ProofState::DIRTY;
}

Try / catch

try {
    $proofState->setSpelling($value);
} catch (\InvalidArgumentException $e) {
    $proofState->setSpelling(ProofState::CLEAN);
}

Prevention

When it happens

Trigger: Calling setSpelling() with a value other than ProofState::CLEAN or ProofState::DIRTY, e.g. true/false, 0/1, or strings like 'ok' or 'checked', directly or through a style array.

Common situations: Passing booleans to indicate proof state; using lowercase literals with different casing; porting values from other document libraries that use different enums.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of PHPOffice/PHPWord@aef95c0415 (2026-09-14). Data as JSON: /api/errors/198532aed58912fb. Report an issue: GitHub.

Appendix: source

Thrown at src/PhpWord/ComplexType/ProofState.php:66

     * Grammatical Checking State.
     *
     * @var string
     */
    private $grammar;

    /**
     * Set the Spell Checking State (dirty or clean).
     *
     * @param string $spelling
     *
     * @return self
     */
    public function setSpelling($spelling)
    {
        if ($spelling == self::CLEAN || $spelling == self::DIRTY) {
            $this->spelling = $spelling;
        } else {
            throw new InvalidArgumentException('Invalid value, dirty or clean possible');
        }

        return $this;
    }

    /**
     * Get the Spell Checking State.
     *
     * @return string
     */
    public function getSpelling()
    {
        return $this->spelling;
    }

    /**
     * Set the Grammatical Checking State (dirty or clean).
     *

View on GitHub (pinned to aef95c0415)