{"record":{"id":"c77e3f3aaeb09bf9","repo":"PHPOffice/PHPWord","slug":"invalid-property-propkey","errorCode":null,"errorMessage":"Invalid property '$propkey'","messagePattern":"Invalid property '\\$propkey'","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/PhpWord/Element/Field.php","lineNumber":226,"sourceCode":"     * Get Field type.\n     *\n     * @return string\n     */\n    public function getType()\n    {\n        return $this->type;\n    }\n\n    /**\n     * Set Field properties.\n     *\n     * @return self\n     */\n    public function setProperties(array $properties = [])\n    {\n        foreach (array_keys($properties) as $propkey) {\n            if (!(isset($this->fieldsArray[$this->type]['properties'][$propkey]))) {\n                throw new InvalidArgumentException(\"Invalid property '$propkey'\");\n            }\n        }\n        $this->properties = array_merge($this->properties, $properties);\n\n        return $this;\n    }\n\n    /**\n     * Get Field properties.\n     *\n     * @return array\n     */\n    public function getProperties()\n    {\n        return $this->properties;\n    }\n\n    /**","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/Element/Field.php#L208-L244","documentation":"Field::setProperties() merges the given property map into the field's properties, but first validates each property key against the per-type 'properties' list in $fieldsArray. Any key not defined for the current field type throws InvalidArgumentException. This prevents emitting field instructions Word cannot parse.","triggerScenarios":"Passing a properties array to new Field() or $field->setProperties(['Foo' => 'bar']) where 'Foo' is not in $fieldsArray[$this->type]['properties'], including properties valid for a different field type.","commonSituations":"Copying properties between field types (e.g. using \\* MERGEFORMAT-style keys on a field that doesn't define them), typos like 'Formt' instead of 'Format', or setting properties before setType().","solutions":["Use only property keys listed under your field's entry in Field::$fieldsArray['TYPE']['properties'].","Ensure setType() is called (or the type passed to the constructor) before setProperties(), since validation depends on $this->type.","Fix the key spelling / casing; keys are case-sensitive.","Catch InvalidArgumentException when properties come from external configuration."],"exampleFix":"// before\n$field->setProperties(['Format' => 'MERGEFORMAT']);\n// after\n$field->setProperties(['Format' => 'UPPER']);","handlingStrategy":"validation","validationCode":"if (!isset($allowedProps[$type])) $allowedProps = [];\n$invalid = array_diff(array_keys($properties), array_keys($allowedProps[$type]));\nif ($invalid) { throw new DomainException('Unknown properties: ' . implode(',', $invalid)); }","typeGuard":"function isStringKeyedProps(array $p): bool { foreach ($p as $k => $v) { if (!is_string($k)) return false; } return true; }","tryCatchPattern":"try { $field->setProperties($props); } catch (\\InvalidArgumentException $e) { $field->setProperties(array_intersect_key($props, $known)); }","preventionTips":["Check the field's entry in $fieldsArray before setting properties","Set the field type first so validation runs against the right list","Avoid reusing property maps across different field types"],"tags":["phpword","invalid-argument","field","properties"],"backgroundTag":"invalid-enum-value","analyzedSha":"aef95c04151b5633cc505f672ddd6a71da900ee1","analyzedAt":"2026-09-14T10:53:58.933Z","contentChangedAt":"2026-09-14T10:53:58.933Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}