php.net |  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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: donatj at gmail dot com
New email:
PHP Version: OS:

 

 [2020-06-24 19:47 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-24 19:55 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2020-06-24 19:55 UTC] nikic@php.net
This is allowed for backwards compatibility reasons. Private abstract functions in traits are only supported since PHP 8.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Nov 29 14:01:24 2020 UTC