3

Since I'm a C#-/.NET-guy, I'm used to explicit interface implementations - like so:

public interface IBar
{
    bool Bacon();
}

public class Foo : IBar
{
    bool IBar.Bacon() {}
}

Question:
Is this possible to do in php?

Edit:
To clarify, this is implicit (while what I want, and what is in the above example, is explicit):

public class Foo : IBar
{
    bool Bacon() {}
}
5
  • You mean something like this? php.net/manual/en/language.oop5.interfaces.php Commented Apr 11, 2012 at 9:16
  • The only thing I have found there is implicit implementations. Or have I missed something? Commented Apr 11, 2012 at 9:18
  • Sorry, I didn't realize that there's some kind of distinction. I hope this is only .NET-related stuff, otherwise I would feel really stupid now! Commented Apr 11, 2012 at 9:23
  • Oh, no worry. Think about it this way: If I were to inherit from two interfaces that shared a common signature, there would be a problem if I invoked the signature without casting to the interface. Commented Apr 11, 2012 at 9:25
  • 1
    Alright, I see :) Well, I don't know if this is exactly what you're looking for (or if I really got it right), but I use to work around things like that with namespaces (de2.php.net/manual/en/language.namespaces.rationale.php). So if you put both interfaces in different namespaces, you can still use them both in one place, explicitly addressing them throught their namespaces. But since C# is completely based on namespaces, I guess this is not quite what you're looking for... :) Commented Apr 11, 2012 at 9:32

1 Answer 1

6

PHP supports interfaces, so yes it is possible: http://php.net/manual/en/language.oop5.interfaces.php

PHP does not distinguish between implicit and explicit implementations.

Sign up to request clarification or add additional context in comments.

4 Comments

There is no information whatsoever about explicit implementations in the link you provided.
Sorry, I'm a PHP guy (.NET days long past), and there is no distinction in the PHP world, so I assumed you ware just looking for interfaces.
No worry. You say "there is no distinction", does that mean there is no way to implement a signature explicitly?
Just discovered there wasn't any accepted answers; Add that last comment to your answer and you'll have another answer to your rep :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.