Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What were the reasons of introducing interface in php?

we know, in java, interface was introduced to solve the ambiguity problem arises due to multiple inheritance and we also know, php does not support multiple inheritance the way java or other oop languages support. in php, we can achieve multiple inheritance only through interface. so my question is what's the need of introducing INTERFACE in php, though we can achieve interface kind of things through abstract classes or normal inheritance?

user-image
Question ajoutée par Rashid Anwar , senior php developer , sparx it solution pvt ltd.
Date de publication: 2014/03/02
Muhammad Majid Saleem
par Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

The entire point of interfaces is to give you the flexability to have your class be forced to implement multiple interfaces, but still not allow multiple inheritance. The issues with inheriting from multiple classes are many and varied and the wikipedia page on it sums them up pretty well.

Interfaces are a compromise. Most of the problems with multiple inheritance don't apply to abstract base classes, so most modern languages these days disable multiple inheritance yet call abstract base classes interfaces and allows a class to "implement" as many of those as they want.

Mohamed saleh
par Mohamed saleh , PHP Laravel Developer , babeleye

it really the solution for single inheritance programming languages as the class can only inherits form only one class but after providing the Interface the class can implement many interfaces with the extended class.

Mudassar Ali Fayyaz
par Mudassar Ali Fayyaz , software architect , Ciklum

Interface helps to provide one with contract that a class implement particular interface has these functionalities.

Interface helps to implement D part of SOLID principle, which states that object should depend on abstract then concrete. In

Emad Mohammed said abdalla
par Emad Mohammed said abdalla , ERP & IT Software, operation general manager . , AL DOHA Company

PHP code can be simply mixed with HTML code, or it can be used in combination with various templating engines and web frameworks. PHP code is usually processed by a PHP interpreter, which is usually implemented as a web server's native module or a Common Gateway Interface (CGI) executable. After the PHP code is interpreted and executed, the web server sends resulting output to its client, usually in form of a part of the generated web page – for example, PHP code can generate a web page's HTML code, an image, or some other data. PHP has also evolved to include a command-line interface (CLI) capability and can be used in standalone graphical applications.

The canonical PHP interpreter, powered by the Zend Engine, is free software released under the PHP License. PHP has been widely ported and can be deployed on most web servers on almost every operating system and platform, free of charge.

Despite its popularity, no written specification or standard exists for the PHP language; instead, the canonical PHP interpreter serves as a de facto standard. However, work on creating a formal specification has started in2014.

More Questions Like This