Req #67310 [NEW]: Allow abstract private functions in traits

From: Date: Tue, 20 May 2014 11:41:05 +0000
Subject: Req #67310 [NEW]: Allow abstract private functions in traits
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185874@lists.php.net to get a copy of this message
From: chrisb at zedcore dot com Operating system: Debian GNU/Linux "wheezy" PHP version: 5.4.28 Package: Scripting Engine problem Bug Type: Feature/Change Request Bug description:Allow abstract private functions in traits 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(); -- Edit bug report at https://bugs.php.net/bug.php?id=67310&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67310&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67310&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67310&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=67310&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=67310&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=67310&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=67310&r=needscript Try newer version: https://bugs.php.net/fix.php?id=67310&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=67310&r=support Expected behavior: https://bugs.php.net/fix.php?id=67310&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=67310&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=67310&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=67310&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67310&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=67310&r=dst IIS Stability: https://bugs.php.net/fix.php?id=67310&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=67310&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=67310&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=67310&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=67310&r=mysqlcfg

« previous php.bugs (#185874) next »