使用特征或继承扩展PHP库?

As a software developer I want to provide an extended library for my customers. The original library of the library provider should not be changed.

There are several ways to do this. Traits come into mind but also inheritance.

Assuming there is a class in the original library defined as:

class Super {}

First approach: Extending the original library using traits:

trait MyTrait {
    public function func() {
        echo "func in MyTrait
";
    }
}

// Customer writes in his code:
class Sub1 extends Super {
    use MyTrait;
}
$sub1 = new Sub1;
$sub1->func();

Second approach:Extending the original library using inheritance:

class LibExtension extends Super {
    public function func() {
        echo "func in LibExtension
";
    }
}

// Customer writes in his code:
class Sub2 extends LibExtension {
}

$sub2 = new Sub2;
$sub2->func();

What are advantages of using traits vs. inheritace in this scenario? Which approach is more limited in which case? Which one gives more flexibility for me as software developer or the customer?

Is there any difference in these approaches if we are in the open source or closed source domain?

Are there better approaches for this scenario?

It is very difficult to recommend some approach over another one, but in many cases composition is more suitable way of providing flexibility to the end user.

Considering your trait sample:

trait MyTrait {
    public function func() {
        echo "func in MyTrait
";
    }
}

// Customer writes in his code:
class Sub1 extends Super {
    use MyTrait;
}
$sub1 = new Sub1;
$sub1->func();

it could be rewritten as such:

interface FuncPrinterInterface
{
    public function funcPrint();
}

class FuncPrinter implements FuncPrinterInterface
{
    public function funcPrint()
    {
        echo "func in MyTrait
";
    }
}

class UserClass
{
    /**
     * @var FuncPrinterInterface
     */
    protected $printer;

    /**
     * Sub1 constructor.
     *
     * @param FuncPrinterInterface $printer
     */
    public function __construct(FuncPrinterInterface $printer)
    {
        $this->printer = $printer;
    }

    public function doSomething()
    {
        $this->printer->funcPrint();
    }
}

$sub1 = new UserClass(new FuncPrinter());
$sub1->doSomething();