Skip to content

Incorrect behavior of RemoveParentDelegatingConstructorRector #9571

@franck-paul

Description

@franck-paul

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/46ca86bb-337a-4bad-81af-40d1ab7929c8

<?php
class InternalServerException
{
    private Throwable $stack = [];
    public function __construct(string $message = 'Server error', int $code = 500, ?Throwable $previous = null)
    {
        echo 'Error thrown : ' . $message . ' (' . $code . ')';
	if (!is_null($previous)) {
            $this->stack[] = $previous;
        }
    }
}

class BlogException extends InternalServerException
{
    public function __construct(string $message = 'Blog handling error', int $code = 570, ?Throwable $previous = null)
    {
        parent::__construct($message, $code, $previous);
    }
}

Responsible rules

  • RemoveParentDelegatingConstructorRector

Expected Behavior

As the child constructor provide default parameters' values (which may be different than parent's ones) if necessary, I think that the child constructor is still relevant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions