PHPOffice/PHPWord · error · InvalidArgumentException

Invalid value, on of ' . implode(', ', $restartNumbers) . '…

Error message

Invalid value, on of ' . implode(', ', $restartNumbers) . ' possible

What it means

FootnoteProperties::setNumRestart() validates the footnote numbering-restart mode against a whitelist (RESTART_NUMBER_CONTINUOUS, RESTART_NUMBER_EACH_PAGE, RESTART_NUMBER_EACH_SECTION). Any other value throws an InvalidArgumentException listing the valid constants. This guards the value written into the w:numRestart OOXML attribute.

Solutions

  1. Use FootnoteProperties::RESTART_NUMBER_CONTINUOUS, RESTART_NUMBER_EACH_PAGE, or RESTART_NUMBER_EACH_SECTION
  2. Compare your value against the RESTART_NUMBER_* constants at the top of FootnoteProperties.php
  3. Validate user-supplied values against the constant list before calling the setter

Example fix

// before
$props->setNumRestart('eachPage');
// after
$props->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
Defensive patterns

Strategy: validation

Validate before calling

$allowed = [FootnoteProperties::RESTART_NUMBER_CONTINUOUS, FootnoteProperties::RESTART_NUMBER_EACH_PAGE, FootnoteProperties::RESTART_NUMBER_EACH_SECTION];
if (!in_array($numRestart, $allowed, true)) {
    throw new UnexpectedValueException("numRestart must be one of: " . implode(', ', $allowed));
}

Type guard

function isValidNumRestart(?string $v): bool {
    return in_array($v, [FootnoteProperties::RESTART_NUMBER_CONTINUOUS, FootnoteProperties::RESTART_NUMBER_EACH_PAGE, FootnoteProperties::RESTART_NUMBER_EACH_SECTION], true);
}

Try / catch

try {
    $props->setNumRestart($numRestart);
} catch (\InvalidArgumentException $e) {
    $props->setNumRestart(FootnoteProperties::RESTART_NUMBER_CONTINUOUS);
}

Prevention

When it happens

Trigger: Calling setNumRestart() with an arbitrary string such as 'always' or 'page' instead of the class constants RESTART_NUMBER_CONTINUOUS, RESTART_NUMBER_EACH_PAGE, or RESTART_NUMBER_EACH_SECTION, whether directly or via a style/properties array.

Common situations: Translating OOXML numRestart attribute values with wrong casing; guessing the API instead of reading constants; reusing values from another library's footnote API.

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/122dfb73f6faa954. Report an issue: GitHub.

Appendix: source

Thrown at src/PhpWord/ComplexType/FootnoteProperties.php:180

    /**
     * Set the Footnote and Endnote Numbering Starting Value (continuous, eachSect, eachPage).
     *
     * @param  string $numRestart
     *
     * @return self
     */
    public function setNumRestart($numRestart)
    {
        $restartNumbers = [
            self::RESTART_NUMBER_CONTINUOUS,
            self::RESTART_NUMBER_EACH_SECTION,
            self::RESTART_NUMBER_EACH_PAGE,
        ];

        if (in_array($numRestart, $restartNumbers)) {
            $this->numRestart = $numRestart;
        } else {
            throw new InvalidArgumentException('Invalid value, on of ' . implode(', ', $restartNumbers) . ' possible');
        }

        return $this;
    }
}

View on GitHub (pinned to aef95c0415)