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

Bug: Concatenation changes the order of elements by prettyprinter #1041

Open
jorgsowa opened this issue Nov 18, 2024 · 2 comments
Open

Bug: Concatenation changes the order of elements by prettyprinter #1041

jorgsowa opened this issue Nov 18, 2024 · 2 comments

Comments

@jorgsowa
Copy link
Contributor

jorgsowa commented Nov 18, 2024

Given the code:

<?php
('abc' . 1) + 2;

And running the parser on the original and PrettyPrinter format we get different AST.

Original:

array(
    0: Stmt_Expression(
        expr: Expr_BinaryOp_Plus(
            left: Expr_BinaryOp_Concat(
                left: Scalar_String(
                    value: abc
                )
                right: Scalar_Int(
                    value: 1
                )
            )
            right: Scalar_Int(
                value: 2
            )
        )
    )
)

Prettied:

array(
    0: Stmt_Expression(
        expr: Expr_BinaryOp_Concat(
            left: Scalar_String(
                value: abc
            )
            right: Expr_BinaryOp_Plus(
                left: Scalar_Int(
                    value: 1
                )
                right: Scalar_Int(
                    value: 2
                )
            )
        )
    )
)
@nikic
Copy link
Owner

nikic commented Nov 19, 2024

I assume you actually meant:

<?php
('abc' . 1) + 2;

The print is correct for PHP 7, but not for PHP 8, which changed concat precedence.

@jorgsowa
Copy link
Contributor Author

Yes, I meant concatenation, sorry.

Even for a single PHP version, the most recent one 8.4.1, PrettyPrinter changes the precedence of operations and the output is different in two cases:
https://3v4l.org/KD1RL#v8.4.1

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

No branches or pull requests

2 participants