Computer >> Computer tutorials >  >> Programming >> PHP

Passing static methods as arguments in PHP


The same syntax used by is_callable and call_user_func can be used to pass static methods as arguments in PHP.

To pass the static method, the below example can be used −

Example

<?php
   function my_func() {
      echo "Hello there!";
   }
   $variable_name = "my_func";
   var_dump(is_callable($variable_name, false, $callable_name));
   echo $callable_name, "n";
   var_dump(is_callable($variable_name));
?> 

Output

This will produce the following output −

bool(true) my_func bool(true)