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

PregReplaceEModifierRector should work if $pattern is an array #3045

Closed
derflocki opened this issue Mar 22, 2020 · 3 comments · Fixed by #3063
Closed

PregReplaceEModifierRector should work if $pattern is an array #3045

derflocki opened this issue Mar 22, 2020 · 3 comments · Fixed by #3063
Labels

Comments

@derflocki
Copy link
Contributor

Bug Report

Subject Details
Rector version v0.7.7
Installed as composer dependency

The PregReplaceEModifierRector throws Exception if $pattern is an array.

Minimal PHP Code Causing Issue

https://getrector.org/demo/dfc1a6b3-aac1-478f-a8c4-f2d4fb63e98c

Expected Behaviour

It should work, or at least not throw an Exception but rather indicate, that manual intervention might be necessary.

@TomasVotruba
Copy link
Member

What's the expected change?

@derflocki
Copy link
Contributor Author

Given, that all items in $pattern have the /e modifier, the result would be the same as if it was a string:

preg_replace_callback($pattern, $callback, ...);

But since, only one of them COULD match producing the correct output would be tricky.

I have also encounterd that it also fails if $pattern is not "obviously" a string (is composed of function calls):

https://getrector.org/demo/22f5b2b4-0823-48cc-8ce5-8a6b52fa2487

@TomasVotruba
Copy link
Member

I've covered the concat case.

If you find a replacement for https://getrector.org/demo/dfc1a6b3-aac1-478f-a8c4-f2d4fb63e98c, send PR with failing fixture. Just copy one of: https://github.com/rectorphp/rector/tree/master/rules/php55/tests/Rector/FuncCall/PregReplaceEModifierRector/Fixture and add

before
-----
after

code in them.

TomasVotruba added a commit that referenced this issue Nov 11, 2022
rectorphp/rector-src@b31bb42 [Php81] Register uniqid function on NullToStrictStringFuncCallArgRector (#3045)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants