Skip to content

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

@asrubylife

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.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions