From: marijn at suninet dot org
Operating system: Linux
PHP version: 7.4.1
Package: *General Issues
Bug Type: Bug
Bug description:marijn@suninet.org
Description:
------------
Hi,
There seems to be a behaviour difference between extending from abstract
methods vs non-abstract methods for an incompatible declaration:
https://3v4l.org/gkAm1
In PHP >= 7.0 if you have an incompatible declaration PHP will throw a
warning if it's a non-abstract method. However if it's an abstract
method and the incompatible declaration is in an extend of an extend
(but compatible with the abstract class) then in PHP 7.0 and 7.1 nothing
is raised, but since 7.2 a Fatal is raised. This is as far as I can tell
also undocumented behaviour, it's not in the backwards incompatible
changelist, though I assume it's part of some kind of bug fix.
Either way in my test example I would expect both functions to raise a
Warning, or both a Failed, but not one a Warning and one a Fatal, that
is inconsistent. The problem might be that even though
ExtendsExtendedClass is overriding a non-abstract method (since it is
already implemented in ExtendsAbstractClass), the abstract flag is still
set (from AbstractClass) which turns what should be a warning into a
fatal.
Test script:
---------------
<?php
abstract class AbstractClass {
public function notAbstract() {}
public abstract function isAbstract();
}
class ExtendsAbstractClass extends AbstractClass {
public function notAbstract($arg = null) {}
public function isAbstract($arg = null) {}
}
class ExtendsExtendedClass extends ExtendsAbstractClass {
public function notAbstract() {}
public function isAbstract() {}
}
Expected result:
----------------
Either two warnings or two fatals, not a fatal and a warning.
Actual result:
--------------
PHP 7.0 and 7.1:
Warning: Declaration of ExtendsExtendedClass::notAbstract() should be
compatible with ExtendsAbstractClass::notAbstract($arg = NULL) in
/in/gkAm1 on line 16
PHP 7.2+:
Warning: Declaration of ExtendsExtendedClass::notAbstract() should be
compatible with ExtendsAbstractClass::notAbstract($arg = NULL) in
/in/gkAm1 on line 14
Fatal error: Declaration of ExtendsExtendedClass::isAbstract() must be
compatible with ExtendsAbstractClass::isAbstract($arg = NULL) in
/in/gkAm1 on line 15
Process exited with code 255.
--
Edit bug report at https://bugs.php.net/bug.php?id=79120&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79120&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79120&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79120&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79120&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79120&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79120&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79120&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79120&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79120&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79120&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79120&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79120&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79120&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79120&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79120&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79120&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79120&r=mysqlcfg