3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
74.12 ms | 404 KiB | 5 Q