Nathan Nobbe wrote:
On Wed, Apr 30, 2008 at 12:06 PM, Jeremy Privett <[EMAIL PROTECTED]>
wrote:

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.


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.

Reply via email to