<?php class MyService { function preprocess(array &$variables): void { $variables['x'] = 'X'; } } class Drupal { static function service($id): object { return new MyService(); } } class ServiceCallback { static function __callStatic(string $f, array $args) { ['service' => $service_id, 'method' => $method] = unserialize($f); $service = \Drupal::service($service_id); $service->$method(...$args); } } $variables = []; $callback = ['ServiceCallback', serialize(['service' => 'myservice', 'method' => 'preprocess'])]; call_user_func_array($callback, [&$variables]); var_export($variables);
You have javascript disabled. You will not be able to edit any code.