Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure typehints are interfaces, not abstracts #14

Open
judgej opened this issue Dec 2, 2013 · 0 comments
Open

Make sure typehints are interfaces, not abstracts #14

judgej opened this issue Dec 2, 2013 · 0 comments

Comments

@judgej
Copy link
Member

judgej commented Dec 2, 2013

This injection example type-hints an abstract:

public function setTransactionModel(Model\TransactionAbstract $tx_model)

It kind of made sense to me, because extended transactions will derive from this abstract.

However, when creating models based on third-party classes, the ancestry (being a linear line, before PHP 5.5 traits at least) may not come from the abstract declared here. However, if the abstract implements an interface, then a third party model that does not extend any of the models here, can still implement the interface and so be valid for setTransactionModel().

It has taken me a while to realise the subtlety of this, as the abstract felt a lot more "useful" than an interface, but it is clear to me now :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant