We should encourage the use of Interfaces (this is exactly what they're for) instead of checking whether the method exists.

Performance wise the difference is negligible (instanceof is even slightly faster). However, instanceof more clearly communicates intent because we're looking to use the getOwner function in the way that it's defined in that interface. When using method_exists, if someone were to implement getOwner but not return an instance of UserInterface then our code would still fall apart.

Comments

Kingdutch created an issue. See original summary.

kingdutch’s picture

Assigned: kingdutch » Unassigned
Status: Active » Needs review
ronaldtebrake’s picture

Status: Needs review » Fixed

Great work, will be in 5.0 :)

  • ronaldtebrake authored 9c4379d on 8.x-5.x
    Merge pull request #1314 from goalgorilla/bugfix/3047142
    
    Issue #3047142...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.