Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6077825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:45:51+00:00 2026-05-23T10:45:51+00:00

I am having trouble calling a class method from a string in PHP. Here’s

  • 0

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 name.

Here’s how I’d be calling the method normally:

$tags_array = $this->get_tags_for_image($row["id"]);

Here’s how I’m trying but getting an error:

$tags_array = call_user_func('get_images_for_tag', $row["id"]);

I must be missing the scope but I can’t figure out how to call the method.

—-EDIT
Figured out that this calls the method but $row is undefined now I believe

$tags_array = call_user_func(array($this, 'get_images_for_tag'), $row["id"]);

Full code block:

 $images = call_user_func(array($this, 'get_images_for_tag'), $filter);
        foreach ($images as $row){

            $tags_array = call_user_func(array($this, 'get_images_for_tag'), $row["id"]);
            foreach ($tags_array as $tag_row){
                $tags_array[] =  $tag_row["tag"];
            }

            $image_array []= array (
                'url' => $this->gallery_path_url . '/'. $row["name"],
                'thumb_url' => $this->gallery_path_url . '/thumbs/' . 't_'. $row["name"],
                'id' => $row["id"],
                'description' => $row["description"],
                //'url' => $row["url"],
                'tags' => $tags_array
                );
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:45:52+00:00Added an answer on May 23, 2026 at 10:45 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble calling a specific method from another class in my app.
I am having some trouble calling an objective-c class method from a C++ file.
I'm having trouble calling a specific function inside another on class. Example: var class
I'm having trouble calling a non IDispatch method in an ActiveX control that I've
I'm having trouble calling methods from an included module inside a resque worker. In
Calling regex gurus. I'm having some trouble right now with escaping a string in
I'm having some trouble calling a function which is within a class in python.
I'm having trouble with the MyClass::function(); style of calling methods and can't figure out
I'm creating a sub dialog another vendor is calling. I'm having trouble reading the
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.