twigphp/Twig · error · LogicException
When setting the "deprecation_info" option, you need to…
Error message
When setting the "deprecation_info" option, you need to remove the obsolete deprecated options.
What it means
This LogicException is thrown when both the modern 'deprecation_info' option and the obsolete 'deprecated' (and related 'deprecating_package'/'alternative') options are set at once. The library forbids combining them to avoid ambiguity about which deprecation description is authoritative; the new-style options were introduced in twig/twig 3.15.
Solutions
- Remove the legacy 'deprecated', 'deprecating_package', and 'alternative' options and keep only 'deprecation_info'.
- If you must support older Twig versions, keep the legacy options and drop 'deprecation_info' (a deprecation notice will be triggered).
- Audit custom extension option arrays for both styles after upgrading twig/twig to >= 3.15.
Example fix
// before
new TwigFilter('old', $fn, ['deprecated' => true, 'deprecating_package' => 'acme', 'deprecation_info' => $info]);
// after
new TwigFilter('old', $fn, ['deprecation_info' => $info]); Defensive patterns
Strategy: validation
Validate before calling
$legacy = array_intersect_key($options, array_flip(['deprecated', 'deprecating_package', 'alternative']));
if (isset($options['deprecation_info']) && $legacy) {
$options = array_diff_key($options, $legacy);
} Type guard
function hasConflictingDeprecationOptions(array $options): bool {
return isset($options['deprecation_info']) && (isset($options['deprecated']) || isset($options['deprecating_package']) || isset($options['alternative']));
} Try / catch
try {
$callable = new TwigFilter('x', $fn, $options);
} catch (\LogicException $e) {
unset($options['deprecated'], $options['deprecating_package'], $options['alternative']);
$callable = new TwigFilter('x', $fn, $options);
} Prevention
- During migration, delete legacy keys ('deprecated', 'deprecating_package', 'alternative') in the same commit that adds 'deprecation_info'.
- Centralize callable option building in one factory so both styles cannot be mixed.
- Add a unit test asserting the constructor does not throw for your option sets.
When it happens
Trigger: new TwigFunction/TwigFilter/TwigTest(..., ['deprecated' => true, 'deprecation_info' => $info]) or setting 'deprecating_package'/'alternative' alongside 'deprecation_info'.
Common situations: Incrementally migrating an extension from legacy deprecation options to DeprecatedCallableInfo while leaving the old keys in place; copying config from an older extension when upgrading twig/twig.
Related errors
- The "deprecation_info" option must be an instance of
- Invalid associativity
- You cannot enable the "use_yield" option of Twig as node
- The sandbox requires a strict security policy, call…
- The environment passed to
AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13).
Data as JSON: /api/errors/23a1b1fe9958e51d.
Report an issue: GitHub.
Appendix: source
Thrown at src/AbstractTwigCallable.php:50
'needs_environment' => false,
'needs_context' => false,
'needs_charset' => false,
'needs_is_sandboxed' => false,
'is_variadic' => false,
'always_allowed_in_sandbox' => false,
'deprecation_info' => null,
'deprecated' => false,
'deprecating_package' => '',
'alternative' => null,
], $options);
if ($this->options['deprecation_info'] && !$this->options['deprecation_info'] instanceof DeprecatedCallableInfo) {
throw new \LogicException(\sprintf('The "deprecation_info" option must be an instance of "%s".', DeprecatedCallableInfo::class));
}
if ($this->options['deprecated']) {
if ($this->options['deprecation_info']) {
throw new \LogicException('When setting the "deprecation_info" option, you need to remove the obsolete deprecated options.');
}
trigger_deprecation('twig/twig', '3.15', 'Using the "deprecated", "deprecating_package", and "alternative" options is deprecated, pass a "deprecation_info" one instead.');
$this->options['deprecation_info'] = new DeprecatedCallableInfo(
$this->options['deprecating_package'],
$this->options['deprecated'],
null,
$this->options['alternative'],
);
}
if ($this->options['deprecation_info']) {
$this->options['deprecation_info']->setName($name);
$this->options['deprecation_info']->setType($this->getType());
}
}
View on GitHub (pinned to a414c3a491)