1
public function xyz(){
 echo "Hello";
}

public function abc(){

}

is it possible or not to pass a function as a parameter in PHP; i want to pass xyz function as a parameter of abc function

  • Yes, it is possible – Phil Oct 02 '18 at 05:32
  • ["Semi-duplicate" question](https://stackoverflow.com/questions/2700433/accept-function-as-parameter-in-php) - requires PHP 5.3 or higher, [Callables](http://php.net/manual/en/language.types.callable.php) requre PHP 5.4 or higher. I'd love to elaborate with a full reply, but your question was prematurely closed/duplicate. – paulsm4 Oct 02 '18 at 05:36
  • @MagnusEriksson if you can find any others, let me know and I'll add them up top – Phil Oct 02 '18 at 05:36
  • @Phil - The second added duplicate actually gives a better hint. Otherwise, if there isn't a good duplicate, shouldn't the question rather stay open? Just seems like some questions gets closed a bit too quick. – M. Eriksson Oct 02 '18 at 05:38
  • how to do that plz answer me with code – Muhammad Younas Oct 02 '18 at 05:38
  • @MagnusEriksson don't just stop at the top answer. [This one](https://stackoverflow.com/a/37363617/283366) has details on class methods. I found [another post](https://stackoverflow.com/questions/13543143/passing-an-instance-method-as-argument-in-php) that might help too – Phil Oct 02 '18 at 05:40
  • @paulsm4 the oldest supported version of PHP is 5.6 so it really shouldn't be an issue. See http://php.net/supported-versions.php. And there was nothing _"premature"_ about closing this – Phil Oct 02 '18 at 05:45

0 Answers0