php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: eric at ericstern dot com
New email:
PHP Version: OS:

 

 [2020-07-02 01:41 UTC] eric at ericstern dot com
Description:
------------
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.

https://www.reddit.com/r/PHP/comments/hj61po/php_8_class_inheritance_method_signature/fwmc93e/ and https://php.watch/versions/8.0/lsp-errors#trait 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-02 07:37 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2020-07-02 07:37 UTC] nikic@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 17:01:29 2024 UTC