1

I am getting the error:

Function name must be a string on this code:

$profile_data = $user_data('first_name','last_name','email');

Any ideas why this could be?

5
  • 5
    Spurious $ before user_data? With the dollar sign this syntax is calling a variable function. Commented Oct 11, 2012 at 12:43
  • Your variable is likely an array. What were you trying to accomplish with that specific line? Commented Oct 11, 2012 at 12:43
  • Please add the full error message to your question. Also please provide what var_dump($user_data); outputs if you place it exactly above that line. A related section in the PHP manual is called Variable Functions and might shed some light, too. What is the function (name?) you wanted to call? Commented Oct 11, 2012 at 12:44
  • Possible duplicate of: stackoverflow.com/q/2966129/367456; stackoverflow.com/q/1611709/367456; stackoverflow.com/q/4093305/367456; stackoverflow.com/q/4859228/367456 and many other similar. You need to provide more information (see the var_dump etc) otherwise it's hard to say what exactly causes the error. Commented Oct 11, 2012 at 12:50
  • if $user_data was defined in another function you may need to call it into scope. 'global $user_data;' I just had this issue with $smcFunc['db_query'](...SQL here...) while working in Simple Machines. It gave me the same error on that line because without being called into scope, $smcFunc looks a lot like a function. Commented Feb 22, 2014 at 1:37

2 Answers 2

5

While you can use variables as function-names, to do so requires the variable to be a string.

The variable $user_data sounds more like an array, or even possibly an object. If this is true, you will receive the error specified. Per the comment from @Jon, it could also be possible that user_data() is a method and the $ is a typo.

If none-of-the-above helps, please all relevant code, specifically the creation of the $user_data variable (or a var_dump($user_data) output).

Sign up to request clarification or add additional context in comments.

7 Comments

If $user_data was a variable the syntax would not be even close to legal. So it's not very likely that it is one.
Yes at least this is sort of guessing and providing a test-try answer.
@Jon I've used variables as function names plenty of times; function test() { } $var = 'test'; $var(); will work perfectly fine.
@newfurniturey: Me too. But if that was the case here this question would not have been asked in the first place.
@Jon Check out codepad.org/3OXjXNy9 - same syntax as the OP and same error (minus the line-number, of course). Unless I'm misunderstanding what you're saying (which is very-well possible too =P).
|
0

in php function define following

$profileData =  user_date('first_name','last_name','email');



function user_date($first_name,$last_name,$email){
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.