NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP 5 Interfaces

Chris Snyder chsnyder at gmail.com
Tue May 26 16:35:48 EDT 2009


On Tue, May 26, 2009 at 4:27 PM, Joseph Crawford <codebowl at gmail.com> wrote:
> THanks for pointing that out, I guess I am a bit confused as to why they are
> restricted to public but it answers my question :)
>

The general idea is that everything behind the interface is a black
box, so that a class which implements interface foo can be replaced
with any other class which implements interface foo.

Private methods, being private, are inside of that black box. They
literally don't matter as far as the interface is concerned, because
they can not be called from outside the class.

If you're asking, "Why should I use interfaces?" the answer is
probably only "Because you want to be rigorous and/or satisfy an
externally imposed requirement that you implement particular
interfaces." Most PHP projects are going to be to small and too fluid
to really take advantage of them.

You can get all the benefits of interfaces without actually writing
them out formally by only relying on well-documented public methods
and not accessing properties directly.



More information about the talk mailing list