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 8058093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:14:39+00:00 2026-06-05T09:14:39+00:00

Possible Duplicate: PHP Using a variable when calling a static method I’ve read through

  • 0

Possible Duplicate:
PHP Using a variable when calling a static method

I’ve read through a few different posts on here (I.E. PHP Using a variable when calling a static method) when trying to use a variable on a static function, but I just can’t seem to get the call_user_func_array() function to work the same as if I was able to call the variable directly in the class name.

PHP >= 5.3.0 Method:

$data = $factory_model::by_array(array(
    $form_fields['name_field']  => $value
));

PHP < 5.3.0 Method:

$data = call_user_func_array(array($factory_model, 'by_array'), array(  
    $form_fields['name_field']  => $value
));

It’s some code that I’ve inherited so I can’t change that much on the models, but it should give the following output:

initiative_forecast_type Object
(
    [id:initiative_forecast_type:private] => 0
    [forecast_type:initiative_forecast_type:private] => TRTR
    [tstamp] => 2012-06-11 12:52:07
)

Which it does using the standard PHP 5.3 Method (My user input/value was ‘TRTR’)

But if I use the call_user_func_array method I get:

initiative_forecast_type Object
(
    [id:initiative_forecast_type:private] => 0
    [forecast_type:initiative_forecast_type:private] => 
    [tstamp] => 2012-06-11 12:52:07
)

So it’s not setting the ‘forecast_type’ field. I’ve uploaded the model here – http://pastebin.ca/2160201

For reference – $factory_model = initiative_forecast_type_factory

I thought the 2 call_user_func_array() function should work the same as the 5.3.0 method, but it doesn’t seem to be – Can anyone point me in the right direction?

Thanks!
Christian

  • 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-06-05T09:14:40+00:00Added an answer on June 5, 2026 at 9:14 am

    call_user_func_array() expects the second parameter to be an array of the actual arguments for the function (the keys in the array would be disregarded). What you actually want is call_user_func().

    call_user_func_array('func', array('foo' => 'bar')) === func('bar')
    call_user_func_array('func', array(array('foo' => 'bar'))) === func(array('foo' => 'bar'))
    call_user_func('func', array('foo' => 'bar')) === func(array('foo' => 'bar'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php validate integer Currently I'm using this method: Validate the input using
Possible Duplicate: How to resize an image using PHP? Here's what I've tried: $image
Possible Duplicate: Using a javascript variable to set PHP variable I need to do
Possible Duplicate: Best XML Parser for PHP Using JAXB with Google Android I need
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicate: How to calculate the difference between two dates using PHP? When a
Possible Duplicate: How to calculate the difference between two dates using PHP? how can
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicate: How to convert yyyy-MM-dd HH:mm:ss to “15th Apr 2010” using PHP I
Possible Duplicate: PHP global in functions Using something like this worries me: <? global

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.