|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79731 Public abstract method on trait fulfilled by private method
Submitted: 2020-06-24 19:47 UTC Modified: 2020-06-24 19:55 UTC
From: donatj at gmail dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: master-Git-2020-06-24 (Git) OS: All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-06-24 19:47 UTC] donatj at gmail dot com
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 that the problem exists even in git-master

It is inconsistent with abstract classes or interfaces.

Test script:

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-24 19:55 UTC]
-Status: Open +Status: Wont fix
 [2020-06-24 19:55 UTC]
This is allowed for backwards compatibility reasons. Private abstract functions in traits are only supported since PHP 8.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Jul 02 06:05:44 2022 UTC