Skip to content

PregReplaceEModifierRector doesn't kick in if there's a variable embedded (string interpolation) within the pattern #8920

Closed

Description

@zoliszabo

Hello!

This is from the same old codebase I wrote about earlier, but this time it is actually stepping over without doing the transformation. I tried to figure out the minimal reproducible example below:

 <?php
 
 $pattern = '\d+';
 
-$str = preg_replace("/" . $pattern . "/e", "str_repeat('#', \\1)");
+$str = preg_replace_callback("/" . $pattern . "/", fn($matches): string => str_repeat('#', $matches[1]));
 
 $str = preg_replace("/$pattern/e", "str_repeat('#', \\1)"); // No changes here

Thanks!

Activity

  1. samsonasik commented on Nov 4, 2026

    @samsonasik
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions