Call php class method from string with parameter

后端 未结 3 557
猫巷女王i
猫巷女王i 2021-01-05 09:58

I am having trouble calling a class method from a string in PHP. Here\'s a simple example. Once I get this working I\'ll be using a variable as the method n

相关标签:
3条回答
  • 2021-01-05 10:40

    Try this:

    $tags_array = call_user_func(array($yourClassObj, 'get_images_for_tag'), $row["id"]);
    
    0 讨论(0)
  • 2021-01-05 10:44

    When you want to call a method on an object with call_user_func() you have to pass it an array with the first element as the object or class name that the method will be called on and the second element being the name of the method, e.g.:

    $tags_array = call_user_func( array($this,'get_images_for_tag'), $row["id"]);
    
    0 讨论(0)
  • 2021-01-05 10:48

    Use this :

    call_user_method('get_images_for_tag',$this,$row["id"]);

    0 讨论(0)
提交回复
热议问题