Form validation throws a strict warning I am using the form validation in hook_form_alter() as follows.

$form['#validate'][] = '\Drupal\module_name\Controller\MyController::_field_p_servicename_validate';


In the controller I am defining it as follows.

public function _field_p_servicename_validate(&amp;$form, FormStateInterface $form_state) {}


It throws the following exception.


  Strict warning: call_user_func_array() expects parameter 1 to be a valid callback, non-static method Drupal\module_name\Controller\MyController::_field_p_servicename_validate() should not be called statically in Drupal\Core\Form\FormValidator->executeValidateHandlers() (line 88 of core/lib/Drupal/Core/Form/FormValidator.php)


What does it mean? How can I fix it?
There are contexts where Drupal allows you to use a notation like  '\Drupal\module_name\Controller\MyController::_field_p_rpservicename_validate' to refer to a public function of an object. In the case of validation handlers, since Drupal is calling them with call_user_func_array(), with a notation like '\Drupal\module_name\Controller\MyController::_field_p_rpservicename_validate' you are referring to a static function of a class.

Change  the definition of that method as follows, and your code will work.

public static function _field_p_rpservicename_validate(&amp;$form, FormStateInterface $form_state) {}


Keep in mind that a static method cannot use $this.