Skip to content

throw expression is not parsed correctly inside a ternary #417

@Daimona

Description

@Daimona

Reproducible with the following snippet:

<?php

return rand() ? throw new Exception() : 42;

And test code, using dev-main:

<?php
require __DIR__ . "/vendor/autoload.php";

use Microsoft\PhpParser\Parser;

$parser = new Parser();
$astNode = $parser->parseSourceFile('<?php return rand() ? throw new Exception() : 42;');
print_r($astNode);

The resulting ternary node has an empty ifExpression, the throw expression inside elseExpression, and then the 42 to follow as a separate expression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions