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

Fix consts in default values #985

Merged
merged 1 commit into from
Sep 26, 2022
Merged

Fix consts in default values #985

merged 1 commit into from
Sep 26, 2022

Conversation

malarzm
Copy link
Member

@malarzm malarzm commented Sep 18, 2022

Fixes #983. cc @nicolas-grekas I've added you as co-author :)

Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
$value = preg_split("/('(?:[^'\\\\]*+(?:\\\\.)*+)*+')/", $value, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($value as $i => $part) {
if ($i % 2 === 0) {
$value[$i] = preg_replace('/(?<![a-zA-Z0-9_\x7f-\xff\\\\])[a-zA-Z0-9_\x7f-\xff]++(?:\\\\[a-zA-Z0-9_\x7f-\xff]++|::)++/', '\\\\\0', $part);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think lines 1131, 1134 and 1135 warrant explanations/code comments, I can't say I understand what they do. I've tried dumping $value on line 1133 and it does not seem to do any splitting in the case of the constant. Also, removing the dot in the regex on line 1132 produces no effect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas maybe you can help? What should the preg_split part produce? Why are we acting only on even items of the array it produces?

@malarzm
Copy link
Member Author

malarzm commented Sep 26, 2022

As agreed internally, this PR demonstrably fixes a bug so I'm going to merge and release.

@malarzm malarzm merged commit 616d5fc into 3.4.x Sep 26, 2022
@malarzm malarzm deleted the const-in-default-value branch September 26, 2022 17:15
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 this pull request may close these issues.

3.4.0 broke class constants defaults in methods parameters when using PHP 8.1+
3 participants