Traits
trait Timestampable {
private DateTime \$createdAt;
private DateTime \$updatedAt;
public function initializeTimestamps(): void {
\$this->createdAt = new DateTime();
\$this->updatedAt = new DateTime();
}
}
class Post {
use Timestampable;
}
Conflict Resolution
trait A { public function foo(): void { echo "A"; } }
trait B { public function foo(): void { echo "B"; } }
class MyClass {
use A, B {
A::foo insteadof B;
B::foo as bar;
}
}
Namespaces
namespace App\Services;
use App\Models\User;
use function array_map;
use const PHP_INT_MAX;