tolerant-php-parser icon indicating copy to clipboard operation
tolerant-php-parser copied to clipboard

throw expression is not parsed correctly inside a ternary

Open Daimona opened this issue 7 months ago • 0 comments

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.

Daimona avatar Jun 07 '25 14:06 Daimona