{"record":{"id":"7c0e1dd68ed27854","repo":"twigphp/Twig","slug":"only-iterable-values-can-be-appended-to-inlinestyle","errorCode":null,"errorMessage":"Only iterable values can be appended to InlineStyle.","messagePattern":"Only iterable values can be appended to InlineStyle\\.","errorType":"exception","errorClass":"Twig\\Error\\RuntimeError","httpStatus":null,"severity":"error","filePath":"extra/html-extra/HtmlAttr/InlineStyle.php","lineNumber":48,"sourceCode":"    }\n\n    public function mergeInto(mixed $previous): mixed\n    {\n        if ($previous instanceof self) {\n            return new self([...$previous->value, ...$this->value]);\n        }\n\n        if (is_iterable($previous)) {\n            return new self([...$previous, ...$this->value]);\n        }\n\n        throw new RuntimeError('Attributes using InlineStyle can only be merged with iterables or other InlineStyle instances.');\n    }\n\n    public function appendFrom(mixed $newValue): mixed\n    {\n        if (!is_iterable($newValue)) {\n            throw new RuntimeError('Only iterable values can be appended to InlineStyle.');\n        }\n\n        return new self([...$this->value, ...$newValue]);\n    }\n\n    public function getValue(): ?string\n    {\n        $style = '';\n        foreach ($this->value as $name => $value) {\n            // `0`, `0.0` and `'0'` are valid CSS values, so only the values that carry\n            // no declaration at all are skipped here\n            if (null === $value || false === $value || true === $value || '' === $value || [] === $value) {\n                continue;\n            }\n            if (is_numeric($name)) {\n                $style .= trim($value, '; ').'; ';\n            } else {\n                $style .= $name.': '.$value.'; ';","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/html-extra/HtmlAttr/InlineStyle.php#L30-L66","documentation":"InlineStyle::appendFrom adds new style declarations to this object; the new value must be iterable so it can be spread into the internal declaration list. Passing a non-iterable (string, null, scalar) raises this RuntimeError.","triggerScenarios":"Calling $inlineStyle->appendFrom('font-weight:bold') with a raw string, appendFrom(null), or appendFrom(123).","commonSituations":"Appending a hand-written CSS snippet string instead of an array of declarations.","solutions":["Append an array of declarations, e.g. appendFrom(['font-weight' => 'bold']).","Convert the string to an array first (explode/explode-style parsing).","Use mergeInto with an InlineStyle instance if appending another style object's value."],"exampleFix":"// before\n$style->appendFrom('font-weight:bold');\n// after\n$style->appendFrom(['font-weight' => 'bold']);","handlingStrategy":"type-guard","validationCode":"if (!is_iterable($newValue)) {\n    throw new InvalidArgumentException('appendFrom requires an iterable of declarations');\n}\n$style->appendFrom($newValue);","typeGuard":"function isIterableForStyleAppend(mixed $v): bool {\n    return is_iterable($v);\n}","tryCatchPattern":"try {\n    $style->appendFrom($newValue);\n} catch (\\Twig\\Error\\RuntimeError $e) {\n    if (str_contains($e->getMessage(), 'can be appended to InlineStyle')) {\n        // convert the string to declarations or skip\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Append arrays of declarations, not CSS strings","Parse any raw CSS string into key/value pairs before appending","Validate variables for null before appending"],"tags":["twig","html-extra","inline-style","append","type-error"],"backgroundTag":"type-mismatch","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}