Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do we need interfaces in PHP?
#1
Do we even need interfaces in PHP, or are they just useless, pretentious, performance hampering formalities? Do they have about as much concrete, practical value as wearing a tuxedo while programming?

Well, let’s take the performance issue first. Interfaces will not affect performance much unless we put the interface in a separate file. Opening a file always takes time. So we need to be aware of that.

What interfaces do, in a practical sense, is next to nothing. In fact, if we are not using class type hints and our code is correct, interfaces have zero effect on how the code executes. Interfaces are primarily a way of making things explicit and of preventing
some mistakes.


But although interfaces are not strictly necessary, they may have some value. They make some of our design more explicit and they can prevent some stupid mistakes. But at this writing, interfaces have existed in PHP for too short a time to make firm judgments as to when they will be useful and when they won’t. What we can do is to explore some possible advantages and disadvantages, some insights and some pitfalls
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)