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

  1. Remove the legacy 'deprecated', 'deprecating_package', and 'alternative' options and keep only 'deprecation_info'.
  2. If you must support older Twig versions, keep the legacy options and drop 'deprecation_info' (a deprecation notice will be triggered).
  3. 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

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


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)