The forward_static_call_array Function

The forward_static_call_array function allows you to call a static class method by passing parameters as an array. The first parameter accepts a callable (the class name and method in array or string format), the second - an array of arguments to pass to the method.

Syntax

phpforward_static_call_array(callable $function, array $parameters);

Example

Calling a static class method with parameter passing:

php<?php
  class Calculator {
    public static function add($a, $b) {
      return $a + $b;
    }
  }
  
  $res = forward_static_call_array(['Calculator', 'add'], [5, 3]);
  echo $res;
?>

Code execution result:

php8

Example

Using a string call instead of an array:

php<?php
  class StringHelper {
    public static function concat($str1, $str2) {
      return $str1 . $str2;
    }
  }
  
  $res = forward_static_call_array('StringHelper::concat', ['Hello', 'World']);
  echo $res;
?>

Code execution result:

php'HelloWorld'

See Also