Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

is defined - The variable has been defined, and set to any value (or null).

is not null - The variable has been defined, and is specifically not null.

In PHP terms, it's like the difference between is_null() vs. checking whether the variable exists using get_defined_vars() (see this Stack Overflow threadStack Overflow thread for a little more clarity)


Try this experiment... Without setting myVar, put this in your template:

{{ (myVar is defined) }}

Since that equates to false, nothing will appear in your template. Now change it to this:

{{ (myVar is not null) }}

That will actually throw an error, since myVar was never defined.

is defined - The variable has been defined, and set to any value (or null).

is not null - The variable has been defined, and is specifically not null.

In PHP terms, it's like the difference between is_null() vs. checking whether the variable exists using get_defined_vars() (see this Stack Overflow thread for a little more clarity)


Try this experiment... Without setting myVar, put this in your template:

{{ (myVar is defined) }}

Since that equates to false, nothing will appear in your template. Now change it to this:

{{ (myVar is not null) }}

That will actually throw an error, since myVar was never defined.

is defined - The variable has been defined, and set to any value (or null).

is not null - The variable has been defined, and is specifically not null.

In PHP terms, it's like the difference between is_null() vs. checking whether the variable exists using get_defined_vars() (see this Stack Overflow thread for a little more clarity)


Try this experiment... Without setting myVar, put this in your template:

{{ (myVar is defined) }}

Since that equates to false, nothing will appear in your template. Now change it to this:

{{ (myVar is not null) }}

That will actually throw an error, since myVar was never defined.

Removed misinformation about "is null" not being a test. Reorganized answer to more accurately address the question.
Source Link
Lindsey D
  • 24.1k
  • 5
  • 54
  • 111

is defined - The variable has been defined, and set to any value (potentially evenor null).

is not null - The variable has been defined, and is specifically not null.

In PHP terms, it's like the difference between is_null() vs. checking whether the variable exists using get_defined_vars() (see this Stack Overflow thread for a little more clarity)


Try this experiment... Without setting myVar, put this in your template:

{{ (myVar is defined) }}

Since that equates to false, nothing will appear in your template. Now change it to this:

{{ (myVar is not null) }}

That will actually throw an error, since myVar was never defined.

is defined - The variable has been defined, and set to any value (potentially even null).

is not null - The variable has been defined, and is specifically not null.

In PHP terms, it's like the difference between is_null() vs. checking whether the variable exists using get_defined_vars() (see this Stack Overflow thread for a little more clarity)


Try this experiment... Without setting myVar, put this in your template:

{{ (myVar is defined) }}

Since that equates to false, nothing will appear in your template. Now change it to this:

{{ (myVar is not null) }}

That will actually throw an error, since myVar was never defined.

is defined - The variable has been defined, and set to any value (or null).

is not null - The variable has been defined, and is specifically not null.

In PHP terms, it's like the difference between is_null() vs. checking whether the variable exists using get_defined_vars() (see this Stack Overflow thread for a little more clarity)


Try this experiment... Without setting myVar, put this in your template:

{{ (myVar is defined) }}

Since that equates to false, nothing will appear in your template. Now change it to this:

{{ (myVar is not null) }}

That will actually throw an error, since myVar was never defined.

Removed misinformation about "is null" not being a test. Reorganized answer to more accurately address the question.
Source Link
Lindsey D
  • 24.1k
  • 5
  • 54
  • 111

Yes, it matters.

nullis defined is a value - The variable has been defined but not, and set to anythingany value (potentially even null).

definedis not null means exactly what it says - The variable has been defined, and is specifically not null.

In PHP terms, it's like the difference between is_null() vs. checking whether the variable exists using get_defined_vars() (to any valuesee this Stack Overflow thread for a little more clarity).

 

Try this experiment... Without setting myVar, put this in your template:

{{ (myVar is defined) }}

Since that equates to false, nothing will appear in your template. Now change it to this:

{{ (myVar is not null) }}

That will actually throw an error, since myVar was never defined.

To further elaborate, null is a value (as previously mentioned), while defined is a test.

http://twig.sensiolabs.org/doc/tests/defined.html

In PHP terms, it's like the difference between is_null() vs. checking whether the value exists in get_defined_vars() (see this Stack Overflow thread for a little more clarity)

Yes, it matters.

null is a value - The variable has been defined but not set to anything.

defined means exactly what it says - The variable has been defined (to any value).

Try this experiment... Without setting myVar, put this in your template:

{{ (myVar is defined) }}

Since that equates to false, nothing will appear in your template. Now change it to this:

{{ (myVar is null) }}

That will actually throw an error, since myVar was never defined.

To further elaborate, null is a value (as previously mentioned), while defined is a test.

http://twig.sensiolabs.org/doc/tests/defined.html

In PHP terms, it's like the difference between is_null() vs. checking whether the value exists in get_defined_vars() (see this Stack Overflow thread for a little more clarity)

is defined - The variable has been defined, and set to any value (potentially even null).

is not null - The variable has been defined, and is specifically not null.

In PHP terms, it's like the difference between is_null() vs. checking whether the variable exists using get_defined_vars() (see this Stack Overflow thread for a little more clarity)

 

Try this experiment... Without setting myVar, put this in your template:

{{ (myVar is defined) }}

Since that equates to false, nothing will appear in your template. Now change it to this:

{{ (myVar is not null) }}

That will actually throw an error, since myVar was never defined.

Elaborated
Source Link
Lindsey D
  • 24.1k
  • 5
  • 54
  • 111
Loading
Elaborated
Source Link
Lindsey D
  • 24.1k
  • 5
  • 54
  • 111
Loading
Source Link
Lindsey D
  • 24.1k
  • 5
  • 54
  • 111
Loading