|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-05-22 22:42 UTC] aharvey@php.net
[2014-06-06 12:53 UTC] kjarli at gmail dot com
[2014-06-09 16:31 UTC] aharvey@php.net
-Status: Open
+Status: Assigned
-Assigned To:
+Assigned To: aharvey
[2014-06-09 16:31 UTC] aharvey@php.net
[2014-06-12 14:33 UTC] chrisb at zedcore dot com
[2017-10-24 07:18 UTC] kalle@php.net
-Status: Assigned
+Status: Open
-Assigned To: aharvey
+Assigned To:
[2020-02-07 09:59 UTC] nikic@php.net
-Assigned To:
+Assigned To: nikic
[2020-04-03 10:30 UTC] nikic@php.net
-Status: Assigned
+Status: Closed
[2020-04-03 10:30 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 13:00:02 2025 UTC |
Description: ------------ When using traits, the trait and the class using the trait can both access private members of the class. The trait can also define abstract methods to enforce that the class using the trait implements them. However, it's not (currently) possible to define an abstract private method; it throws a fatal error. I assume this check was add pre-traits, where it obviously didn't make sense to have abstract private methods since they could never be overridden, but traits change this – an abstract private method in a trait *can* be overridden by the class using the trait. Therefore I think that it would make sense for the this check to be changed so that traits can define methods as "abstract private". The test script attached causes a fatal error. Replacing the trait's "MyPrivateMethod" with an empty non-abstract function makes it print out "Hello World" as expected. Test script: --------------- trait MyTrait { abstract private function MyPrivateMethod(); public function MyPublicMethod() { $this->MyMethod(); } } class MyClass { use MyTrait; private function MyPrivateMethod() { echo "Hello World"; } } $o = new MyClass(); $o->MyPublicMethod();