Jump to content

[SOLVED] Interface with private methods


radalin

Recommended Posts

Hi,

 

I'm trying to create an interface with private methods. But when I try to run the file, I get an error:

 

Access type for interface method myInterface::prvfnc() must be omitted in c:\htdocs\file.php on line 12

 

My interface is like this:

 

interface myInterface {
  private function prvfnc();
}

 

and my class is like:

 

class myClass implements myInterface {
  private function prvfnc() {
    echo "private function call";
  }
}

 

Is private methods are not allowed in PHP interfaces?

 

Thanks for your time.

Link to comment
https://forums.phpfreaks.com/topic/134051-solved-interface-with-private-methods/
Share on other sites

The problem is, if I do not define public/private/protected in the interface, it takes the access level of the method as public and in class if I define it as a private function I get an error like this:

 

Access level to myClass::prvfnc() must be public (as in class myInterface) in C:\htdocs\file.php on line 12

 

Is it a bug perhaps?

 

 

Edit: PHP version is 5.2.6

Well, honestly that really makes sense :) Why to define a function which you can never be able to call...

 

But how I'm using the interface is to define which functions must have a class and it looks like more of a blue print than a real interface.

 

But you are quite right about that :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.