Jump to content

PHP Fatal error: Call to undefined


Noongar

Recommended Posts

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;
?>

Link to comment
Share on other sites

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 []

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.