Jump to content


Photo

eval() boolean statement


  • Please log in to reply
2 replies to this topic

#1 Uranium-235

Uranium-235
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 30 July 2006 - 01:08 AM

This has been bugging me.

I'm testing if a list of varibles (from a seperate list)I get from extract() from MySQL query is equal to "Y". Do a boolean compairason for each one (this is from a much larger thing). I'm calling this inside a function call

I keep getting "Parse error: parse error, unexpected $ in /home/thescriptwholedirectoryremoved.php(781) : eval()'d code on line 1"

here is the statement I use:

eval("return (\$" . $key . " == \"Y\")")

when I actually print the evaluated statement in PHP, it prints out as:
return ($carreq == "Y")

which is correct, but, eval gives me an error. please help
Random Quote:[br][br][url=http://www.paintbug.com/scripts/quote_source.phps]

#2 DepretioN

DepretioN
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 July 2006 - 01:57 AM

return eval("return ($" . $key . " == 'Y');");


#3 Uranium-235

Uranium-235
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 30 July 2006 - 02:09 AM

thank you.

can you please explain why I got that error. earlier (before i posted here) I even took out the $ completly just cause I was getting pissed, and it still said "Unexpected $". How could it be unexpected, there was no $ at all.

edit: ahhh, it was the semicolon. I had no idea I would have to put one in there on a bool compairason. I don't for my other ones (of course for those, I was passing them alone as an argument), but appearently you have to for eval with a return statement. Thank you
Random Quote:[br][br][url=http://www.paintbug.com/scripts/quote_source.phps]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users