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
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: 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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC