|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79768 LSP BC break in 8.0.0 issues no warning in 7.x
Submitted: 2020-07-02 01:41 UTC Modified: 2020-07-02 07:37 UTC
From: eric at ericstern dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 7.4.7 OS: n/a
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: eric at ericstern dot com
New email:
PHP Version: OS:


 [2020-07-02 01:41 UTC] eric at ericstern dot com
Both abstract trait method validation and promotion of warnings to fatal errors for LSP violation have been implemented in PHP 8. Yay!

Unfortunately due to the timing of these two changes, it can result in a new fatal error where previously there was no warning/notice issued at all. This can catch people upgrading by surprise, and is rather difficult to track down in any sort of automated way. and provide more context and examples.

Test script:
trait MyTrait {
  abstract protected function foo(): string;

class MyClass {
  use MyTrait;
  protected function foo()

Expected result:
Some sort of warning/notice/etc for abstract trait validation is back-ported from 8.0.0, so that the (expected) fatal error the same code would produce under 8 isn't a complete surprise for projects running on modern 7.x.

I recognize this would go against normal conventions and RFC processes for new warnings/errors/deprecations, but given the impact it can have when trying to upgrade, I think it's well worth considering making a process exception.

Actual result:
7.4.7: no warning, error, notice, etc.

8.0.0-alpha1: fatal error


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-02 07:37 UTC]
-Status: Open +Status: Wont fix
 [2020-07-02 07:37 UTC]
Sorry, backporting such a warning to PHP 7.4 is forbidden by policy.

Automated tooling will be able to diagnose this change in the future. I think it is a bit early to expect static analyzers to have complete PHP 8 support at this point in time.

If you do encounter this issue, there is an extremely simple quick fix: Just comment the abstract method. (Usually making using classes compatible would be the proper fix, but it may be more involved.)
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jun 21 17:01:23 2021 UTC