Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php convert string to method call

Tags:

php

<?php
  $str = "getList";

  //now by doing something to $str i need to call getList() method any sugesstions 

  function getList(){
    echo "get list called";
  }
?>
like image 241
Sekhar Avatar asked Dec 13 '25 04:12

Sekhar


1 Answers

Use the call_user_func() function to call the function by name.

like image 192
axel_c Avatar answered Dec 14 '25 19:12

axel_c



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!