In PHP, how do I copy traits with SPL?

This example demonstrates how to copy traits in PHP using the Standard PHP Library (SPL).

PHP, SPL, traits, object-oriented programming, code reuse

This example illustrates how to copy traits in PHP, showcasing the use of SPL for efficient code organization and reuse.

<?php
trait TraitA {
public function sayHello() {
return "Hello from TraitA!";
}
}
trait TraitB {
public function sayGoodbye() {
return "Goodbye from TraitB!";
}
}
class MyClass {
use TraitA, TraitB;
}
$obj = new MyClass();
echo $obj->sayHello(); // Output: Hello from TraitA!
echo $obj->sayGoodbye(); // Output: Goodbye from TraitB!
?>

PHP SPL traits object-oriented programming code reuse