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

 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)

Updated on: 07-Apr-2020

495 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements