sspence65 Posted March 13, 2013 Share Posted March 13, 2013 I'm clearly doing something wrong. I ported this piece of code from one I wrote in VBScript (where it works great), but I'm not as familiar with php syntax. Hopefully you can see where I'm going with this. I want to end up with a variable that contains the string of Sh0413C $monthCode = array("02", "03", "04", "06", "09", "10", "10", "11", "11", "12", "12", "01"); $monthLetterCode = array("A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M"); $realMonthCode = date("n"); $labelYearCode = date("y"); $arrayMonthCode = $realMonthCode - 1; $labelMonthCode = $monthCode(arrayMonthCode); $labelLetterCode = $monthLetterCode(arrayMonthCode); $myString = "Sh" . $labelMonthCode . $labelYearCode . $labelLetterCode; Quote Link to comment https://forums.phpfreaks.com/topic/275619-fatal-error-function-name-must-be-a-string/ Share on other sites More sharing options...
Solution DavidAM Posted March 13, 2013 Solution Share Posted March 13, 2013 $monthCode(arrayMonthCode) is telling PHP to use the value in the variable $monthCode as the name of a function to call and pass it the constant named arrayMonthCode. PHP uses square-brackets for array subscripts/keys, and you need the dollar-sign on the subscript to make it a variable reference.$monthCode = array("02", "03", "04", "06", "09", "10", "10", "11", "11", "12", "12", "01"); $monthLetterCode = array("A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M"); $realMonthCode = date("n"); $labelYearCode = date("y"); $arrayMonthCode = $realMonthCode - 1; $labelMonthCode = $monthCode[$arrayMonthCode]; #MAD# Changed $labelLetterCode = $monthLetterCode[$arrayMonthCode]; #MAD# Changed $myString = "Sh" . $labelMonthCode . $labelYearCode . $labelLetterCode;I changed lines 7 and 8. Quote Link to comment https://forums.phpfreaks.com/topic/275619-fatal-error-function-name-must-be-a-string/#findComment-1418449 Share on other sites More sharing options...
sspence65 Posted March 13, 2013 Author Share Posted March 13, 2013 That did the trick. Not including the $ was stupid mistake, but the [ was a revelation, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/275619-fatal-error-function-name-must-be-a-string/#findComment-1418450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.