Compile Error: Cannot use isset() on the result of an expression

Compile Error: Cannot use isset() on the result of an expression

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Compile Error: Cannot use isset() on the result of an expression

When migrating a Symfony application from version 2.0.x to 2.7, you may encounter a FatalErrorException that looks like this:

Compile Error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)

This error points to a compiled Twig template file (e.g., /var/www/html/reptooln_admin/app/cache/dev/twig/68/7f/...). The specific line in the cache is often unreadable, but it usually contains nested logic attempting to chain multiple checks on the same variable. In your case, the generated PHP code looks like this:

if ((((empty((isset($context["form_action"]) ? $context["form_action"] : $this->getContext($context, "form_action"))) == true) || (isnull((isset($context["form_action"]) ? $context["form_action"] : $this->getContext($context, "form_action"))) == true)) || (isset((isset($context["form_action"]) ? $context["form_action"] : $this->getContext($context, "form_action"))) == false))) {
    echo " ";
    $context["form_action"] = "";
    echo " ";
}

The error message is explicit: PHP cannot evaluate isset() on the result of another expression. This happens because you are nesting custom filters—empty, isnull, and isset—directly inside a standard if statement in your Twig template.

The Root Cause: Custom Filters vs. Native Syntax

Your Twig extension defines custom filters for empty, isset, and isnull. You are using them in your template like this:

{% if form_action|empty == true or form_action|isnull == true or form_action|isset == false %}
    {% set form_action = '' %}
{% endif %}

In Symfony 2.0.x, Twig's expression parser was less strict and allowed chaining these custom filters in complex boolean expressions. However, Symfony 2.7 (and later versions) significantly tightened the PHP code generation logic for Twig templates. The compiler attempts to translate your filter chain into a single PHP if statement.

When you write form_action|isset, you are essentially asking Twig to return the result of is_set($value). If you then try to wrap that in another check like empty(...) or pass it into a nested context lookup, the resulting PHP syntax becomes invalid. Specifically, the compiler tries to generate code resembling isset( ... ) where the inner part is already an evaluated boolean expression from your previous filter. PHP does not allow passing the result of a function call (that returns a boolean) directly into isset().

The Fix: Simplify Your Logic

The solution is to stop chaining these custom filters in a single condition. Instead, evaluate each state independently or rely on native Twig syntax where possible.

First, remove the custom filters if you don't need them. Symfony's native default filter and standard PHP logic handle missing variables gracefully. If your goal is simply to check if form_action is empty or null, rewrite the condition without nesting:

{% set value = form_action %}
{% if value is empty or value is null %}
    {% set form_action = '' %}
{% endif %}

If you must use your custom filters for legacy compatibility reasons, ensure they are applied in a way that returns the original value or a simple boolean without being nested inside another function call. However, relying on native Twig logic is the recommended approach for modern Symfony projects.

Understanding the Trade-off

Why did this work in 2.0.x but fail in 2.7? The earlier version of Twig allowed more flexible, albeit messy, expression parsing. It often generated verbose PHP that worked around syntax limitations. Symfony 2.7 improved the compiler to generate cleaner, standard-compliant PHP code. While this means older "hacks" or complex filter chains break, it also ensures your templates are portable and less prone to obscure runtime errors.

Migration Advice

When moving from SF 2.0.x to newer versions, avoid creating custom filters that mimic native PHP functions like isset, empty, or is_null. These functions have specific behaviors in PHP that are difficult to replicate perfectly within the expression language without side effects.

Instead, leverage Twig's native type testing operators (is even, is defined, is empty). They are performant and generate clean code. If you find yourself needing complex logic, consider moving that logic into a dedicated controller method or a service rather than keeping it inside the template. This keeps your templates readable and prevents the compiler from generating unreadable cache files.

If you are maintaining legacy templates during this migration, search for patterns where filters are chained directly in if statements. Refactoring those lines to use separate variable assignments or native is tests will resolve the compile errors and align your codebase with modern Symfony standards.

Our network