PHPOffice/PHPWord · error · InvalidArgumentException
Invalid value, on of ' . implode(', ', $position) . '…
Error message
Invalid value, on of ' . implode(', ', $position) . ' possible What it means
FootnoteProperties::setPos() validates the footnote position against a fixed whitelist (POSITION_PAGE, POSITION_SECTION, POSITION_DOC_END). If the passed value is not one of these class constants, an InvalidArgumentException is thrown listing the valid options. The message contains a typo ('on of' instead of 'one of') but the intent is clear: only the documented constants are accepted.
Solutions
- Use one of the class constants: FootnoteProperties::POSITION_PAGE, POSITION_SECTION, or POSITION_DOC_END
- Check spelling/casing of the value against the constants defined at the top of FootnoteProperties.php
- Wrap the call in try-catch InvalidArgumentException if the value comes from user input, and fall back to the default
Example fix
// before
$props->setPos('end');
// after
$props->setPos(FootnoteProperties::POSITION_DOC_END); Defensive patterns
Strategy: validation
Validate before calling
$allowed = [FootnoteProperties::POSITION_PAGE, FootnoteProperties::POSITION_SECTION, FootnoteProperties::POSITION_DOC_END];
if (!in_array($pos, $allowed, true)) {
throw new UnexpectedValueException("pos must be one of: " . implode(', ', $allowed));
} Type guard
function isValidFootnotePos(?string $pos): bool {
return in_array($pos, [FootnoteProperties::POSITION_PAGE, FootnoteProperties::POSITION_SECTION, FootnoteProperties::POSITION_DOC_END], true);
} Try / catch
try {
$props->setPos($pos);
} catch (\InvalidArgumentException $e) {
$props->setPos(FootnoteProperties::POSITION_PAGE); // safe default
} Prevention
- Always use FootnoteProperties::POSITION_* constants, never raw strings
- Pre-validate user/config input against the constant list
- Write a unit test covering each allowed position value
When it happens
Trigger: Calling setPos() (directly or via FootnoteProperties constructor/style array, e.g. Section->addFootnote with footnoteProperties) with an arbitrary string like 'end' or 'document' instead of FootnoteProperties::POSITION_PAGE, POSITION_SECTION, or POSITION_DOC_END.
Common situations: Guessing the position string instead of using the class constants; copying XML attribute values from OOXML docs (e.g. 'docEnd' vs 'docEnd' casing variants) into the setter; typos in config arrays passed to style builders.
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
- Invalid value, on of ' . implode(', ', $restartNumbers) . '…
- Invalid value, dirty or clean possible
- Invalid value, alignments of ' . implode(', '…
- Cannot set a Comment on a Comment
- Invalid style value
AI-assisted analysis of PHPOffice/PHPWord@aef95c0415 (2026-09-14).
Data as JSON: /api/errors/1e75a0af858e1c09.
Report an issue: GitHub.
Appendix: source
Thrown at src/PhpWord/ComplexType/FootnoteProperties.php:97
* Set the Footnote Positioning Location (pageBottom, beneathText, sectEnd, docEnd).
*
* @param string $pos
*
* @return self
*/
public function setPos($pos)
{
$position = [
self::POSITION_PAGE_BOTTOM,
self::POSITION_BENEATH_TEXT,
self::POSITION_SECTION_END,
self::POSITION_DOC_END,
];
if (in_array($pos, $position)) {
$this->pos = $pos;
} else {
throw new InvalidArgumentException('Invalid value, on of ' . implode(', ', $position) . ' possible');
}
return $this;
}
/**
* Get the Footnote Numbering Format.
*
* @return string
*/
public function getNumFmt()
{
return $this->numFmt;
}
/**
* Set the Footnote Numbering Format.
*View on GitHub (pinned to aef95c0415)