Jump to content

[SOLVED] Interface with private methods


Recommended Posts



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
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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.