What is the difference between a contract in Laravel and an interface in PHP?

As far as I can tell, Laravel refers to the interfaces that it extends as contracts because they are used by Laravel. But this is like circular reasoning. There is no added value when changing the terminology of an existing PHP function simply because its project uses it.

Is there anything else? What is the logic of creating a new term for something that is a standard PHP function? Or is there some feature of contracts that are not yet in the interfaces?

Change To clarify, this is the use of the Contract as a proper noun in the documentation, which confused me, as explained in my comment on Thomas post

+6
source share
3 answers

This is just a nice word to describe the idea of โ€‹โ€‹using interfaces.

Laravel contracts are simply PHP interfaces, so they do not provide any other functions.

You can read more about this in the documentation http://laravel.com/docs/5.1/contracts

+7
source

โ€œContractโ€ is not some new terminology that Taylor came up with. This is a very common term that programmers use.

An interface is a contract, but a contract does not have to be an interface. The interface in a nutshell defines the contract that classes should implement.

An abstract class is also a contract. The difference is that an abstract class can provide actual implementations, state, etc., and as a result it is (in a sense) a more strict contract.

Another key difference is that a child class can extend only 1 abstract class, but it can implement several interfaces.

Thus, a โ€œcontractโ€ is not a new naming convention. This is a general term that Taylor uses.

+13
source

As others have said, it's just a fancy word for interfaces, but I think Taylor made this decision to make it more personal.

What I mean by personal is that an interface is a very broad / general word in a programming language, you have interfaces, libraries (which you can use) have their own interfaces, etc.

Contracts that you only assume, since Laravel interacts with it as a shell or alias for all interfaces that belong to this repo .

+2
source

All Articles