php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28158 Can't declare function protected in interface
Submitted: 2004-04-26 15:44 UTC Modified: 2004-04-26 17:43 UTC
From: dcahh at gmx dot de Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2004-04-26 (dev) OS: XP Pro
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: dcahh at gmx dot de
New email:
PHP Version: OS:

 

 [2004-04-26 15:44 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-26 17:34 UTC] wez@php.net
interfaces are, by definition, public.
Abstract classes are not the same as interfaces.
 [2004-04-26 17:43 UTC] dcahh at gmx dot de
Yes, but is it correct that one can not declare a protected function in an abstract class as long as same implements an interface?
 [2004-07-29 04:08 UTC] ah08010-zend at yahoo dot com
Interfaces need, at a minimum, the ability to regulate the default public "interface" of their implementors.

This includes specifically UNpublicizing the "default" public methods:  __(con|de)struct, __call, __get, __set, etc.

Even if the interface vs. abstract class is valid, it should still be possible to mark __construct as private for e.g., Singleton behavior.

=Austin
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 08:01:32 2024 UTC