Skip to content

Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector casts array to string #9447

Description

@asrubylife

Bug Report

Subject Details
Rector version Rector 2.1.2

preg_replace third argument is casted to string even if the third parameter is an array.

$items = preg_replace($pattern, $replacement, (string)$items);

Minimal PHP Code Causing Issue

<?php

class Field
{

  private static function _replace(&$items) {

      $pattern = "/((\d+')/";
      $replacement = '$1';
      $items = preg_replace($pattern, $replacement, $items);
  }

  public static function getValue($field, $id) {
    $cfg = ['f' => ['id' => 'test']];
    if (!isset($cfg[$field][$id])) return '';
    $new_field = array($cfg[$field][$id]);
    self::_replace($new_field);
    return $new_field[0];
  }
}

Expected Behaviour

it should be casted to an array or left as is.

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions