I've been trying to study up on PHP lately, and I find myself getting hung up on traits. I understand the concept of horizontal code reuse and not wanting to necessarily inherit from an abstract class. What I don't understand is: What is the crucial difference between using traits versus interfaces?
I've tried searching for a decent blog post or article explaining when to use one or the other, but the examples I've found so far seem so similar as to be identical.
An interface defines a set of methods that the implementing class must implement.
When a trait is
use
'd the implementations of the methods come along too--which doesn't happen in anInterface
.That is the biggest difference.
From the Horizontal Reuse for PHP RFC: