Passing static methods as arguments in PHP 

PHPServer Side ProgrammingProgramming

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

 Live Demo

<?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)
raja
Published on 07-Apr-2020 12:57:18
Advertisements