<?php trait aTrait { public static function build($x) { return new static($x); } } class A { public function __construct($x) { $this->x = $x; } use aTrait; } class B { public function __construct($x) { $this->x = $x * 2; } use aTrait; } $a = A::build(2); $b = B::build(2); var_dump($a); var_dump($b);
You have javascript disabled. You will not be able to edit any code.