3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface FormStateInterface {} class FormState implements FormStateInterface {} class Config {} class ConfigFormBase { public function submitForm(array &$form, FormStateInterface $form_state) { print "original"; } } trait ValidatableConfigFormTrait { abstract protected static function mapFormValuesToConfig(FormStateInterface $form_state, Config $config): void; public function submitForm(array &$form, FormStateInterface $form_state) { print "trait"; } } class MyForm extends ConfigFormBase { use ValidatableConfigFormTrait; protected static function mapFormValuesToConfig(FormStateInterface $form_state, Config $config): void { // without this, PHP will complain! 👍 } } $form = []; (new MyForm())->submitForm($form, new FormState());
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
trait

preferences:
53.99 ms | 406 KiB | 5 Q