NullCoalesceNode example


                new Node\GetAttrNode(new Node\NameNode('foo')new Node\ConstantNode('bar', true, true)new Node\ArgumentsNode(), Node\GetAttrNode::METHOD_CALL),
                'foo?.bar()',
                ['foo'],
            ],
            [
                new Node\GetAttrNode(new Node\NameNode('foo')new Node\ConstantNode('not', true, true)new Node\ArgumentsNode(), Node\GetAttrNode::METHOD_CALL),
                'foo?.not()',
                ['foo'],
            ],
            [
                new Node\NullCoalesceNode(new Node\GetAttrNode(new Node\NameNode('foo')new Node\ConstantNode('bar', true)new Node\ArgumentsNode(), Node\GetAttrNode::PROPERTY_CALL)new Node\ConstantNode('default')),
                'foo.bar ?? "default"',
                ['foo'],
            ],
            [
                new Node\NullCoalesceNode(new Node\GetAttrNode(new Node\NameNode('foo')new Node\ConstantNode('bar')new Node\ArgumentsNode(), Node\GetAttrNode::ARRAY_CALL)new Node\ConstantNode('default')),
                'foo["bar"] ?? "default"',
                ['foo'],
            ],

            // chained calls             [
                


    /** * @return Node\Node */
    protected function parseConditionalExpression(Node\Node $expr)
    {
        while ($this->stream->current->test(Token::PUNCTUATION_TYPE, '??')) {
            $this->stream->next();
            $expr2 = $this->parseExpression();

            $expr = new Node\NullCoalesceNode($expr$expr2);
        }

        while ($this->stream->current->test(Token::PUNCTUATION_TYPE, '?')) {
            $this->stream->next();
            if (!$this->stream->current->test(Token::PUNCTUATION_TYPE, ':')) {
                $expr2 = $this->parseExpression();
                if ($this->stream->current->test(Token::PUNCTUATION_TYPE, ':')) {
                    $this->stream->next();
                    $expr3 = $this->parseExpression();
                } else {
                    $expr3 = new Node\ConstantNode(null);
                }
Home | Imprint | This part of the site doesn't use cookies.