Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PrettyPrinter brokes nested ternaries #718

Closed
rentalhost opened this issue Sep 30, 2020 · 1 comment
Closed

PrettyPrinter brokes nested ternaries #718

rentalhost opened this issue Sep 30, 2020 · 1 comment

Comments

@rentalhost
Copy link

Code like:

<?php ( $a ? $b : $c ) ? $d : $e;

Is parsed correctly:

array(
    0: Stmt_Expression(
        expr: Expr_Ternary(
            cond: Expr_Ternary(
                cond: Expr_Variable( name: a )
                if: Expr_Variable( name: b )
                else: Expr_Variable( name: c )
            )
            if: Expr_Variable( name: d )
            else: Expr_Variable( name: e )
        )
    )
)

But PrettyPrinter will outputs:

<?php $a ? $b : $c ? $d : $e;

So if you run the code it will gives:

Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`
@rentalhost
Copy link
Author

php-parser issue 718.zip

composer update
php index.php

@rentalhost rentalhost changed the title PrettyPrinter brokes complex ternaries PrettyPrinter brokes nested ternaries Sep 30, 2020
@nikic nikic closed this as completed in eff72ee Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant