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
https://forums.phpfreaks.com/topic/258831-php-fatal-error-call-to-undefined/
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 []

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.