Skip to content

Make sure typehints are interfaces, not abstracts #14

@judgej

Description

@judgej

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 :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions