Skip to content

#[Override] being a fatal E_COMPILE_ERROR leads to bad usability/update hell #20879

@kkmuffme

Description

@kkmuffme

Description

The following code:
https://3v4l.org/5bkAg#v8.5.1

<?php

class A {
    public function run_new() {}
}

class B extends A {
    #[Override]
    public function run() {}
}

Resulted in this output:

Fatal error: B::run() has #[\Override] attribute, but no matching parent method exists

But I expected this output instead:

Warning: B::run() has #[\Override] attribute, but no matching parent method exists

A and B are from 2 different libraries/packages/plugins
"A" cannot know that "B" used #[Override] so they just removed the method in a new version. Now if "A" is updated by the user (be it via composer where the common ^1.2 syntax is used, or be it a WordPress/Drupal/... plugin) the user now has a broken application.
Even if "B" has a new version that has the #[Override] attribute removed, it would be necessary to first update "B" before updating "A" and to actually know about this issue in advance before updating.
Since E_COMPILE_ERROR is fatal, any update commands or UI won't work either - also composer.lock is useless, since it already contains the updated "A". Which means that you need to completely reinstall it (removing composer.lock and vendor), which results in likely different versions of other packages than you had installed before unless your composer.json is extremely tightly versioned and updated and therefore other issues.
If it's a CMS plugin, you essentially are required to manually either downgrade "A" (if thats even possible) or manually via FTP update "B".

Since there's no real "harm" in there being no matching parent method/property and since other attributes like #[NoDiscard] also result in a warning instead of a fatal, I think the E_COMPILE_ERROR of the Override attribute should be changed - retroactively for PHP 8.3 + 8.4 too, as they are most likely affected by this, being older versions and running code that will have updates available - to a warning only.

PHP Version

8.3+

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions