Tales of an IT Nobody

devbox:~$ iptables -A OUTPUT -j DROP

Interfaces in PHP are worthless. Blasphemy? yes. June 6, 2011

What is the purpose of an interface? One would simply say “they’re a contract, etc.”, and you’d be right.

Long story short, all PHP interfaces do – is enforce:

– What methods are implemented
– What their signatures look like

However there’s one HUGE (in my book) fundamental lack: RETURN TYPES.

Thus, I will call interfaces ‘half a contract’.

The PHP developers and contributors often examine other ‘big brother’ languages to determine some direction for the PHP OO offerings. I think this is where this half-assed implementation came from – an aspiration of the language trying too hard to implement features of strongly typed langauges.

Need examples?


PHP misses a very important component of the ‘contract’, return types. In Java / C#  you can define your methods as such:

public string foo() {}

Now, if you’re willing to shell out for the honor system of implementation or to add some spice to your inductive reasoning – go for it. For what little an interface really does for you, it’s not worth the added complexity and lack of piece of mind interfaces in PHP bring to the table.

I believe that in the current state of PHP, developers will end up implementing additional checks and balances to ensure interface implementors are still behaving correctly.

Categories: php programming

Leave a Reply

Your email address will not be published. Required fields are marked *