# why interfaces ?

- Thread: https://externals.io/message/37359
- Original archive: https://news-web.php.net/php.internals/37359
- Started by Nathan Nobbe on 2008-04-30T16:21:49+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #37359 — Nathan Nobbe — 2008-04-30T16:21:49+00:00

URL: https://externals.io/message/37359#37359

all,

in recent weeks there has been a lot of arguing about what interfaces are,
arent (on php-general and now on the internals list as well) etc. etc.

i am quite curious, why interfaces were added to the language in the first
place.  note, i am not criticizing them, i am overjoyed that the language
has them, however i am curious about the history.  is this something php
borrowed from java?  does it have anything to do with 'entirely virtual
classes' in c++ ?  i think that the history behind the addition of
interfaces to php, would shed a lot of light on their intended purpose for
use by php developers.

thanks,

-nathan

---

## #37378 — Jeremy Privett — 2008-04-30T18:06:41+00:00

URL: https://externals.io/message/37359#37378 · In reply to: #37359

Nathan Nobbe wrote:
> all,
>
> in recent weeks there has been a lot of arguing about what interfaces are,
> arent (on php-general and now on the internals list as well) etc. etc.
>
> i am quite curious, why interfaces were added to the language in the first
> place.  note, i am not criticizing them, i am overjoyed that the language
> has them, however i am curious about the history.  is this something php
> borrowed from java?  does it have anything to do with 'entirely virtual
> classes' in c++ ?  i think that the history behind the addition of
> interfaces to php, would shed a lot of light on their intended purpose for
> use by php developers.
>
> thanks,
>
> -nathan
>
>   

"Interfaces" exist in different OO-enabled languages. PHP strengthened 
its object model in PHP 5, and thus the introduction of interfaces. I'm 
pretty sure the intended purpose of interfaces was just like pretty much 
every other language. You implement interfaces in order to provide a 
consistent API. As long as class A implements interface B, I can be for 
certain that it's going to contain methods C and D. Interfaces also give 
you the ability to "type hint" against them, requiring objects that 
implement that interface, thus ensuring you know what methods are on 
that object.

Interfaces are a very powerful feature, when implemented properly.

-- 
Jeremy Privett
C.E.O. & C.S.A.
Omega Vortex Corporation

http://www.omegavortex.net

Please note: This message has been sent with information that could be confidential and meant only for the intended recipient. If you are not the intended recipient, please delete all copies and inform us of the error as soon as possible. Thank you for your cooperation.

---

## #37379 — Nathan Nobbe — 2008-04-30T18:12:34+00:00

URL: https://externals.io/message/37359#37379 · In reply to: #37378

On Wed, Apr 30, 2008 at 12:06 PM, Jeremy Privett <jeremy@omegavortex.net>
wrote:

> Nathan Nobbe wrote:
>
> > […]
>
> "Interfaces" exist in different OO-enabled languages. PHP strengthened its
> object model in PHP 5, and thus the introduction of interfaces. I'm pretty
> sure the intended purpose of interfaces was just like pretty much every
> other language. You implement interfaces in order to provide a consistent
> API. As long as class A implements interface B, I can be for certain that
> it's going to contain methods C and D. Interfaces also give you the ability
> to "type hint" against them, requiring objects that implement that
> interface, thus ensuring you know what methods are on that object.
>
> Interfaces are a very powerful feature, when implemented properly.


thank you for you response Jeremy.  i understand what interfaces are and i
have stressed their importance and power on php-general more than once.  im
just curious more about what influenced the addition of them to php.  im not
as old as many of them members in the community, so i know there are many
people who have dealt with more languages than i on a daily basis during
their careers.  from my limited base of knowledge, i think java was the
first language to add the keyword 'interface'.  and my presumption is that
that grew from the convention of creating 'interfaces' in c++ by writing
entirely virtual classes (as mentioned in gang of four).  i have heard
different perspectives on this, but i figured, what better place to get to
the bottom of it than to ask the people who decided to add the interface
construct to php in the first place.

-nathan

---

## #37381 — Jeremy Privett — 2008-04-30T18:21:26+00:00

URL: https://externals.io/message/37359#37381 · In reply to: #37379

Nathan Nobbe wrote:
> On Wed, Apr 30, 2008 at 12:06 PM, Jeremy Privett <jeremy@omegavortex.net>
> wrote:
>
>   
> > […]
>
>
> thank you for you response Jeremy.  i understand what interfaces are and i
> have stressed their importance and power on php-general more than once.  im
> just curious more about what influenced the addition of them to php.  im not
> as old as many of them members in the community, so i know there are many
> people who have dealt with more languages than i on a daily basis during
> their careers.  from my limited base of knowledge, i think java was the
> first language to add the keyword 'interface'.  and my presumption is that
> that grew from the convention of creating 'interfaces' in c++ by writing
> entirely virtual classes (as mentioned in gang of four).  i have heard
> different perspectives on this, but i figured, what better place to get to
> the bottom of it than to ask the people who decided to add the interface
> construct to php in the first place.
>
> -nathan
>
>   

Absolutely. I vaguely remember the discussion on php-general, though I 
don't think I participated. I think Java was the first language to 
implement the keyword, but the concept has definitely been around since 
C++. If I had to guess, the reasoning was probably that it felt a 
natural part of the object model, possibly influenced from Java. The 
whole reason I asked the other question previously about the properties 
in interfaces is because I've been working in C# lately, and it allows 
implementing properties in interfaces. I never needed the functionality 
before, but now that I've actually used it in another language, I've 
found a use-case for it and attempted in PHP only to find that it 
resulted in a fatal error. Thus, the inquiry to php-internals.

-- 
Jeremy Privett
C.E.O. & C.S.A.
Omega Vortex Corporation

http://www.omegavortex.net

Please note: This message has been sent with information that could be confidential and meant only for the intended recipient. If you are not the intended recipient, please delete all copies and inform us of the error as soon as possible. Thank you for your cooperation.

---

## #37382 — Robert Cummings — 2008-04-30T18:29:13+00:00

URL: https://externals.io/message/37359#37382 · In reply to: #37359

> all,
> 
> in recent weeks there has been a lot of arguing about what interfaces are,
> arent (on php-general and now on the internals list as well) etc. etc.
> 
> i am quite curious, why interfaces were added to the language in the first
> place.  note, i am not criticizing them, i am overjoyed that the language
> has them, however i am curious about the history.  is this something php
> borrowed from java?  does it have anything to do with 'entirely virtual
> classes' in c++ ?  i think that the history behind the addition of
> interfaces to php, would shed a lot of light on their intended purpose for
> use by php developers.

The answer is in the archives. I haven't gone back to review them, but I
remember vaguely they were originally going with multiple inheritance
before they switched directions after much discussion and took the
interface route instead.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP
