ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Node_Expression_NullCoalesce Class Reference
+ Inheritance diagram for Twig_Node_Expression_NullCoalesce:
+ Collaboration diagram for Twig_Node_Expression_NullCoalesce:

Public Member Functions

 __construct (Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
- Public Member Functions inherited from Twig_Node_Expression_Conditional
 __construct (Twig_Node_Expression $expr1, Twig_Node_Expression $expr2, Twig_Node_Expression $expr3, $lineno)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
- Public Member Functions inherited from Twig_Node
 __construct (array $nodes=array(), array $attributes=array(), $lineno=0, $tag=null)
 Constructor. More...
 
 __toString ()
 
 toXml ($asDom=false)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
 getTemplateLine ()
 
 getLine ()
 
 getNodeTag ()
 
 hasAttribute ($name)
 
 getAttribute ($name)
 
 setAttribute ($name, $value)
 
 removeAttribute ($name)
 
 hasNode ($name)
 
 getNode ($name)
 
 setNode ($name, $node=null)
 
 removeNode ($name)
 
 count ()
 
 getIterator ()
 
 setTemplateName ($name)
 
 getTemplateName ()
 
 setFilename ($name)
 
 getFilename ()
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
 getLine ()
 
 getNodeTag ()
 

Additional Inherited Members

- Protected Attributes inherited from Twig_Node
 $nodes
 
 $attributes
 
 $lineno
 
 $tag
 

Detailed Description

Definition at line 11 of file NullCoalesce.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node_Expression_NullCoalesce::__construct ( Twig_NodeInterface  $left,
Twig_NodeInterface  $right,
  $lineno 
)

Definition at line 13 of file NullCoalesce.php.

14 {
16 new Twig_Node_Expression_Test_Defined(clone $left, 'defined', new Twig_Node(), $left->getTemplateLine()),
18 $left->getTemplateLine()
19 );
20
21 parent::__construct($test, $left, $right, $lineno);
22 }
$test
Definition: Utf8Test.php:84
Checks if a variable is defined in the current context.
Definition: Defined.php:25
Checks that a variable is null.
Definition: Null.php:22
Represents a node in the AST.
Definition: Node.php:19
$lineno
Definition: Node.php:22
getTemplateLine()
Definition: Node.php:121

References Twig_Node\$lineno, and $test.

Member Function Documentation

◆ compile()

Twig_Node_Expression_NullCoalesce::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Reimplemented from Twig_Node_Expression_Conditional.

Definition at line 24 of file NullCoalesce.php.

25 {
26 /*
27 * This optimizes only one case. PHP 7 also supports more complex expressions
28 * that can return null. So, for instance, if log is defined, log("foo") ?? "..." works,
29 * but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced
30 * cases might be implemented as an optimizer node visitor, but has not been done
31 * as benefits are probably not worth the added complexity.
32 */
33 if (PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof Twig_Node_Expression_Name) {
34 $this->getNode('expr2')->setAttribute('always_defined', true);
35 $compiler
36 ->raw('((')
37 ->subcompile($this->getNode('expr2'))
38 ->raw(') ?? (')
39 ->subcompile($this->getNode('expr3'))
40 ->raw('))')
41 ;
42 } else {
43 parent::compile($compiler);
44 }
45 }
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:112
getNode($name)
Definition: Node.php:186

References Twig_Node\getNode(), and Twig_Compiler\raw().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: