Skip to content

Conversation

TomasVotruba
Copy link
Contributor

@TomasVotruba TomasVotruba commented Jan 22, 2019

Adds ??= support php/php-src#3747

Tests are failing.

It looks like it's not possible to add it. Probably needs to wait for T_COALESCE_EQUAL token, or not?

@TomasVotruba TomasVotruba changed the title Add coalesce assign [PHP 7.4] Add coalesce assign Jan 22, 2019
@TomasVotruba TomasVotruba changed the title [PHP 7.4] Add coalesce assign [PHP 7.4] Add coalesce equal ??= Jan 22, 2019
@nikic
Copy link
Owner

nikic commented Jan 22, 2019

Yes, it should use T_COALESCE_EQUAL. If we run on a PHP version that does not have it, then we need to emulate it in Lexer\Emulative, by combining a T_COALESCE and a '=' token into a T_COALESCE_ASSIGN token.

@TomasVotruba
Copy link
Contributor Author

Thanks for navigation. I dig through history and blame and tried to inspire at: 251e689

Emulative parsers seems to work, but grammer still looks broken. Any clue?

@nikic
Copy link
Owner

nikic commented Jan 23, 2019

Not sure what's up with the test failure. Token 392 on PHP 7.1 is E_ERROR, but I don't really see why it would occur in this situation.

@TomasVotruba
Copy link
Contributor Author

Thanks for review, I'll integrate it and see it helped with the error.

@TomasVotruba
Copy link
Contributor Author

TomasVotruba commented Jan 23, 2019

Now the parser is rebuild without error 👍

Yet the error still remains:

1) PhpParser\PrettyPrinterTest::testPrettyPrint with data set "var/www/PHP-Parser/test/code/prettyPrinter/expr/operators_php7.test#0" ('Basic operators (/var/www/PHP....test)', '<?php\n\n$a ??= $c;', '$a ??= $c;', 'php7')
RangeException: The lexer returned an invalid token (id=281, value=??=)

Test fixture - operators_php7.test:

Basic operators
-----
<?php

$a ??= $c;
-----
!!php7
$a ??= $c;

@TomasVotruba
Copy link
Contributor Author

Any tips what tests should I add?

@nikic
Copy link
Owner

nikic commented Jan 30, 2019

Okay, I believe this issue here is that the token is not used in the PHP 5 parser and thus gets dropped from the translation table. It would be fine if you just add support for ??= to the PHP 5 parser as well.

One thing that's missing here is a parser test for ??=. If ??= is supported in the PHP 5 parser as well, you can just add it into test/code/parser/expr/assign.test.

@TomasVotruba
Copy link
Contributor Author

It would be fine if you just add support for ??= to the PHP 5 parser as well.

Works like a charm!

One thing that's missing here is a parser test for ??=. If ??= is supported in the PHP 5 parser as well, you can just add it into test/code/parser/expr/assign.test.

👍 I'm on it

@nikic
Copy link
Owner

nikic commented Feb 9, 2019

Merged as 9de9682. Thanks :)

@nikic nikic closed this Feb 9, 2019
@TomasVotruba TomasVotruba deleted the null-collesce-assign branch February 9, 2019 11:55
@TomasVotruba
Copy link
Contributor Author

👍 Thank you

@TomasVotruba
Copy link
Contributor Author

Any ETA for release of this? I'd love to test in Rector and real code to demonstrace PHP 5.3 → 7.4 upgrade

@nikic
Copy link
Owner

nikic commented Feb 16, 2019

@TomasVotruba
Copy link
Contributor Author

TomasVotruba commented Feb 16, 2019

Wow! Thank you ❤️

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 this pull request may close these issues.

2 participants