Traits vs. interfaces

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 … Read more

How to override trait function and call it from the overridden function?

Scenario: trait A { function calc($v) { return $v+1; } } class MyClass { use A; function calc($v) { $v++; return A::calc($v); } } print (new MyClass())->calc(2); // should print 4 This code doesn’t work, and I cannot find a way to call a trait function like it was inherited. I tried calling self::calc($v), static::calc($v), … Read more