Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eval return value 2

Status
Not open for further replies.

vbkris

Programmer
Joined
Jan 20, 2003
Messages
5,994
Location
IN
i have a function:
function ASD()
{
return "AD";
}

another function:
function asd1()
{
$vl=eval("AD();")
echo $vl;
}

$vl is empty(even though a value is returned)... why?

is there a workaround?

Known is handfull, Unknown is worldfull
 
Is it just a typo or did you mean to call the function AD() instead of ASD()?
 
oops its a typo:
i want to call ASD()
$vl=eval("ASD();")


Known is handfull, Unknown is worldfull
 
Your eval should read
[tt]$vl = eval("return ASD();");[/tt]

//Daniel
 
Your string that is evaluated does not contain a return reference. The function which you defined does - but that oly works inside the function.

What you need to do is to return the result of ASD():
Code:
$vl = eval("return AD();");

The internal return only returns the result of the function and has no bearing for the eval() function.
 
Ur right...

but can u tell me why i need another return in the eval?

Known is handfull, Unknown is worldfull
 
oops i couldnt read DRJ's post...

i have read it only now...

DRJ:
>>but that only works inside the function

what does this mean?

Known is handfull, Unknown is worldfull
 
Ok,

You asked for it. Here is a more verbose answer.

Functions return values to a caller. That's the nature of (most) functions, including your ASD(). When you call ASD() the function returns the value you assigned inside the function.
Just doing eval("ASD()"); is like a simple assignment. You could think about it as
Code:
eval("$myvalue = ASD();");

Now you can see that the evaluated code actually does not return anything, because it is not told to, it just executes the function.

In order to return the result of the function as the result of the eval() function the return statement must be in the evaluated code.

Visualize eval as:
Code:
function eval(){
  # do something like
  $myVar = ASD();
  return $theResult;
}
 
yup..

i got it...

so eval() doesnt return anything (ur function eval() expalained it all....)

thanks...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top