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

Parenthesis before nullsafe operator #1154

Open
czuniga9 opened this issue Jan 24, 2025 · 1 comment
Open

Parenthesis before nullsafe operator #1154

czuniga9 opened this issue Jan 24, 2025 · 1 comment
Labels

Comments

@czuniga9
Copy link

Good day, first thanks for the awesome project!

I noticed the parser fails if you have something between parenthesis before a nullsafe operator. I found it when using code like

echo ($published_at ?? $last_modified_at)?->format('M d, Y');

but it fails even with

($published_at)?->format('M d, Y');

Here's a small example:

const engine = require("php-parser");
const parser = new engine();
const code = parser.parseEval('$a = null; echo ($a)?->format();');

And here's the output:

test/node_modules/php-parser/src/parser.js:357
    throw err;
    ^

SyntaxError: Parse Error : syntax error, unexpected '?->' (T_NULLSAFE_OBJECT_OPERATOR), expecting ';' on line 1
    at Parser.raiseError (test/node_modules/php-parser/src/parser.js:349:17)
    at Parser.error (test/node_modules/php-parser/src/parser.js:397:15)
    at Parser.expectEndOfStatement (test/node_modules/php-parser/src/parser.js:508:10)
    at Parser.read_statement (test/node_modules/php-parser/src/parser/statement.js:279:14)
    at Parser.read_top_statement (test/node_modules/php-parser/src/parser/statement.js:78:21)
    at Parser.read_start (test/node_modules/php-parser/src/parser/main.js:18:19)
    at Parser.parse (test/node_modules/php-parser/src/parser.js:301:22)
    at Engine.parseEval (test/node_modules/php-parser/src/index.js:146:22)
    at Object.<anonymous> (test/test.js:3:21)
    at Module._compile (node:internal/modules/cjs/loader:1546:14) {
  lineNumber: 1,
  fileName: 'eval',
  columnNumber: 20
}

Node.js v22.7.0
@czosel czosel added the bug label Jan 24, 2025
@czosel
Copy link
Collaborator

czosel commented Jan 24, 2025

Hi @czuniga9, thanks for the bug report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants