Noongar Posted March 13, 2012 Share Posted March 13, 2012 Does anyone know why I am getting PHP Fatal error: Call to undefined function ABCDEFGHIJKLMNOPQRSTUVWXYZ()? <?php $capitals = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $capitalsinteger = rand(1-26); $capital = $capitals($capitalsinteger); $lowercases = 'abcdefghijklmnpqrstuvwxyz'; $lowercasesinteger = rand(1-26); $lowercase = $lowercases($lowercasesinteger); $firstnamelowercaseslength = rand(5-10); $firstnamelowercaseslengthcounter = 0; $randomizedfirstnamelowercases = ''; firstname: $randomizedfirstnamelowercases .= $lowercase; $firstnamelowercaseslengthcounter++; if ($firstnamelowercaseslengthcounter != $firstnamelowercaseslength) { goto firstname; } echo $capital.$randomizedfirstnamelowercases; ?> Quote Link to comment https://forums.phpfreaks.com/topic/258831-php-fatal-error-call-to-undefined/ Share on other sites More sharing options...
The Little Guy Posted March 13, 2012 Share Posted March 13, 2012 because the function doesn't exist, or your not including it in your code Quote Link to comment https://forums.phpfreaks.com/topic/258831-php-fatal-error-call-to-undefined/#findComment-1326816 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2012 Share Posted March 13, 2012 Did you look at the line in your code and try to determine why php thought you were attempting to call a function having a name of the contents of your variable, instead of php treating the variable as an array? Wouldn't that suggest that you need to use array syntax instead of function syntax? The syntax for referencing an array element uses [] Quote Link to comment https://forums.phpfreaks.com/topic/258831-php-fatal-error-call-to-undefined/#findComment-1326824 Share on other sites More sharing options...
Noongar Posted March 13, 2012 Author Share Posted March 13, 2012 If I knew what your asking already, I wouldn't be asking. Thanks for teaching me that [] is associated with arrays. I am grateful. Quote Link to comment https://forums.phpfreaks.com/topic/258831-php-fatal-error-call-to-undefined/#findComment-1326835 Share on other sites More sharing options...
Muddy_Funster Posted March 13, 2012 Share Posted March 13, 2012 to call a php function you generaly use functionName(variableValue), which is exactly what you are doing here: $capital = $capitals($capitalsinteger); let me illustrate with this code: <?php $anynameyoulike = "MyFunction"; function MyFunction($start, $finish){ $number = rand($start,$finish); return $number; } $anyOtherName = MyFunction(1,5); $aThirdName = $anynameyoulike(20,27); echo "$anyOtherName<br><br><br>$aThirdName"; ?> the key lines are the two just above the echo line. see how both MyFunction and $anynameyoulike can both be used to call the function? So your code has PHP looking up what $capitals contains and then trying to find a function with the name that matches the string content of the variable (which we all know it can't do). You need to totaly redesign your code. Quote Link to comment https://forums.phpfreaks.com/topic/258831-php-fatal-error-call-to-undefined/#findComment-1326851 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2012 Share Posted March 13, 2012 LOL, the OP is using an array of letters and randomly selecting an index/letter. He's not trying to call a function and he's not trying to use variable functions. Quote Link to comment https://forums.phpfreaks.com/topic/258831-php-fatal-error-call-to-undefined/#findComment-1326873 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.