Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Does PHP really need interfaces?

Question posted by: Daniel Klein (Guest) on March 17th, 2008 04:45 PM
Seeing as PHP is a dynamic language (like Python and Smalltalk), I don't see
what use an Interface has other than to satisfy a contract.

Why were they even added to the language? Can anyone think of any reason
that that they would be required?

I guess these are more rhetorical questions, but I woke up this morning and
it bothered me so much that I felt like starting a discussion :-)

Daniel Klein
Jerry Stuckle's Avatar
Jerry Stuckle
Guest
n/a Posts
March 17th, 2008
06:45 PM
#2

Re: Does PHP really need interfaces?
Daniel Klein wrote:
Quote:
Seeing as PHP is a dynamic language (like Python and Smalltalk), I don't see
what use an Interface has other than to satisfy a contract.
>
Why were they even added to the language? Can anyone think of any reason
that that they would be required?
>


OO.
Quote:
I guess these are more rhetorical questions, but I woke up this morning and
it bothered me so much that I felt like starting a discussion :-)
>
Daniel Klein
>



They can be very handy, especially when you don't have multiple inheritance.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
Join Bytes!
==================


Michael Fesser's Avatar
Michael Fesser
Guest
n/a Posts
March 18th, 2008
12:25 AM
#3

Re: Does PHP really need interfaces?
..oO(Jerry Stuckle)
Quote:
>Strongly typed has its uses. And programs written in strongly typed
>languages typically have fewer errors. But there is a limit where the
>typing becomes more of an interference than a help (i.e. PASCAL). I
>wish PHP were more strongly typed - but not as strong as PASCAL.


Can you elaborate on that (just a bit, I know it's OT)? I've learned
programming with Pascal and I've never found it to be too restrictive.

On the contrary, I really liked its rules, the additional compiler
checks and enforcements, which helped to avoid many bugs right from the
beginning, because they could often be found at compile time already.
Can you give a short example where you think that Pascal's strong typing
becomes more of an interference?

Micha

Jerry Stuckle's Avatar
Jerry Stuckle
Guest
n/a Posts
March 18th, 2008
12:45 AM
#4

Re: Does PHP really need interfaces?
Michael Fesser wrote:
Quote:
.oO(Jerry Stuckle)
>
Quote:
>Strongly typed has its uses. And programs written in strongly typed
>languages typically have fewer errors. But there is a limit where the
>typing becomes more of an interference than a help (i.e. PASCAL). I
>wish PHP were more strongly typed - but not as strong as PASCAL.

>
Can you elaborate on that (just a bit, I know it's OT)? I've learned
programming with Pascal and I've never found it to be too restrictive.
>
On the contrary, I really liked its rules, the additional compiler
checks and enforcements, which helped to avoid many bugs right from the
beginning, because they could often be found at compile time already.
Can you give a short example where you think that Pascal's strong typing
becomes more of an interference?
>
Micha
>



To keep it short: Pascal puts you in a straitjacket. Without getting
into details, data types must match *exactly*. No implicit conversions
and very limited explicit conversions. C is on the other end - you can
convert almost anything to almost anything, whether it is correct or not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
Join Bytes!
==================


Michael Fesser's Avatar
Michael Fesser
Guest
n/a Posts
March 18th, 2008
02:25 AM
#5

Re: Does PHP really need interfaces?
..oO(Jerry Stuckle)
Quote:
>To keep it short: Pascal puts you in a straitjacket. Without getting
>into details, data types must match *exactly*.


IIRC they just have to be compatible, so you can easily cast one int
type into another. But I haven't used Pascal for years ...
Quote:
>No implicit conversions
>and very limited explicit conversions. C is on the other end - you can
>convert almost anything to almost anything, whether it is correct or not.


Yes, and we know the results. Many things that you can do in C are
simply not possible in Pascal - for good reasons. I liked that.

But OK, that's completely OT here.

Micha

The Natural Philosopher's Avatar
The Natural Philosopher
Guest
n/a Posts
March 18th, 2008
10:05 AM
#6

Re: Does PHP really need interfaces?
Michael Fesser wrote:
Quote:
.oO(Jerry Stuckle)
>
Quote:
>Strongly typed has its uses. And programs written in strongly typed
>languages typically have fewer errors. But there is a limit where the
>typing becomes more of an interference than a help (i.e. PASCAL). I
>wish PHP were more strongly typed - but not as strong as PASCAL.

>
Can you elaborate on that (just a bit, I know it's OT)? I've learned
programming with Pascal and I've never found it to be too restrictive.
>

Ruddy nightmare. I had to (re write in C eventually) a Pascal program to
decode a stream of mixed bits, bytes and blocks of data.

I didn't succeed.

Thats why I rewrote it in C. Possibly it is posible to create the
equivalent of a uninin in Pascal, but I didn't have time to work out how,

Quote:
On the contrary, I really liked its rules, the additional compiler
checks and enforcements, which helped to avoid many bugs right from the
beginning, because they could often be found at compile time already.
Can you give a short example where you think that Pascal's strong typing
becomes more of an interference?
>


See above.
Quote:
Micha


The Natural Philosopher's Avatar
The Natural Philosopher
Guest
n/a Posts
March 18th, 2008
10:05 AM
#7

Re: Does PHP really need interfaces?
Jerry Stuckle wrote:
Quote:
Michael Fesser wrote:
Quote:
>.oO(Jerry Stuckle)
>>
Quote:
>>Strongly typed has its uses. And programs written in strongly typed
>>languages typically have fewer errors. But there is a limit where
>>the typing becomes more of an interference than a help (i.e.
>>PASCAL). I wish PHP were more strongly typed - but not as strong as
>>PASCAL.

>>
>Can you elaborate on that (just a bit, I know it's OT)? I've learned
>programming with Pascal and I've never found it to be too restrictive.
>On the contrary, I really liked its rules, the additional compiler
>checks and enforcements, which helped to avoid many bugs right from the
>beginning, because they could often be found at compile time already.
>Can you give a short example where you think that Pascal's strong typing
>becomes more of an interference?
>>
>Micha
>>

>
>
To keep it short: Pascal puts you in a straitjacket. Without getting
into details, data types must match *exactly*. No implicit conversions
and very limited explicit conversions. C is on the other end - you can
convert almost anything to almost anything, whether it is correct or not.
>

C is in the middle. You can convert anything to anything, but very
seldom IMPLICITLY.

PHP converts anything to anything invisibly and implicitly, which means
you have to KNOW the rules of its implicit conversions.

Tim Roberts's Avatar
Tim Roberts
Guest
n/a Posts
March 19th, 2008
07:05 AM
#8

Re: Does PHP really need interfaces?
Daniel Klein <danielk@featherbrain.netwrote:
Quote:
>Seeing as PHP is a dynamic language (like Python and Smalltalk), I don't see
>what use an Interface has other than to satisfy a contract.
>
>Why were they even added to the language? Can anyone think of any reason
>that that they would be required?
>
>I guess these are more rhetorical questions, but I woke up this morning and
>it bothered me so much that I felt like starting a discussion :-)


My uneducated guess is that they were added to allow PHP to play more
directly in the CORBA/COM world.
--
Tim Roberts, Join Bytes!
Providenza & Boekelheide, Inc.

 
Not the answer you were looking for? Post your question . . .
190,062 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors