Bug #79731 [Opn->Wfx]: Public abstract method on trait fulfilled by private method
| From: | nikic@php.net | Date: | Wed, 24 Jun 2020 19:55:14 +0000 |
| Subject: | Bug #79731 [Opn->Wfx]: Public abstract method on trait fulfilled by private method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227638@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79731&edit=1
ID: 79731
Updated by: nikic@php.net
Reported by: donatj at gmail dot com
Summary: Public abstract method on trait fulfilled by private
method
-Status: Open
+Status: Wont fix
Type: Bug
Package: Scripting Engine problem
Operating System: All
PHP Version: master-Git-2020-06-24 (Git)
Block user comment: N
Private report: N
New Comment:
This is allowed for backwards compatibility reasons. Private abstract functions in traits are only
supported since PHP 8.
Previous Comments:
------------------------------------------------------------------------
[2020-06-24 19:47:27] donatj at gmail dot com
Description:
------------
A public abstract method declaration on a trait is fulfilled by a private method on a
'use'-ing class. This seems like an incorrect behaviour.
You can see on https://3v4l.org/a65oD that the problem exists
even in git-master
It is inconsistent with abstract classes or interfaces.
Test script:
---------------
<?php
trait ATrait {
abstract public function foo( string $url ) : int;
}
class AClass {
use ATrait;
private function foo( string $url ) : int {
return 10;
}
}
Expected result:
----------------
Behave either like interfaces:
"Fatal error: Access type for interface method ATrait::foo() must be omitted in - on line
4"
Similar to interfaces
OR like an abstract class:
"Fatal error: Access level to ATrait::foo() must be public (as in class ParentClass) in - on
line 8"
Actual result:
--------------
No error
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79731&edit=1