Skip to content

throw expression is not parsed correctly inside a ternary #417

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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