#28158 [Bgs]: Can't declare function protected in interface

From: Date: Mon, 26 Apr 2004 15:43:49 +0000
Subject: #28158 [Bgs]: Can't declare function protected in interface
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-58790@lists.php.net to get a copy of this message
ID: 28158 User updated by: dcahh at gmx dot de Reported By: dcahh at gmx dot de Status: Bogus Bug Type: Class/Object related Operating System: XP Pro PHP Version: 5CVS-2004-04-26 (dev) New Comment: Yes, but is it correct that one can not declare a protected function in an abstract class as long as same implements an interface? Previous Comments: ------------------------------------------------------------------------ [2004-04-26 17:34:41] wez@php.net interfaces are, by definition, public. Abstract classes are not the same as interfaces. ------------------------------------------------------------------------ [2004-04-26 15:44:22] dcahh at gmx dot de Description: ------------ I can't have an abstract class provide it's functions protected to it's child classes, since I'm able to declare only public functions within an interface. Reproduce code: --------------- <?php interface AnyClassInterface { protected function doSomething ($sTest); } abstract class AnyClassAbstract { protected function doSomething ($sTest) { echo $sTest; } } class AnyClass { public funtion __construct() { $this->doSomething ('Hello World'); } } $oAnyObject = new AnyClass(); ?> Expected result: ---------------- One should be able to declare a function in an interface to be protected, so that classes extending the abstract class, which is implementing the interface is able to provide it's functions only to child-classes and to protect them from foreign classes. Actual result: -------------- Fatal error: Access type for interface method AnyClassInterface::doSomething() must be omitted or declared public in D:\apache-webroot\test\testphp\php5.php on line 5 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28158&edit=1

« previous php.bugs (#58790) next »