rain13 Posted February 14, 2013 Share Posted February 14, 2013 I am trying to eval if condition but for somereason ""itworks" never gets printed. When you call my_if(true||false); directly, it'll return true but not when you eval code.Does anyone know how to eval expression of trues and falses to get only 1 true or false? <?phpfunction my_if($cond){ return $cond;}if(eval("my_if(true||false);")){ print("itworks\n");}?> Examples (let T be true and F be false):T||T shall give TT||F shall give TT&&(T||F) shall give T since (T||F) is T therefore T &&T is T Link to comment Share on other sites More sharing options...
jeffman Posted February 14, 2013 Share Posted February 14, 2013 What are you really asking? Your function does NOTHING, and eval is not necessary. The logical operators you are using (&& and ||)are all you should need. Link to comment Share on other sites More sharing options...
rain13 Posted February 14, 2013 Author Share Posted February 14, 2013 I finally got it work. I had to use return(...); instead. My goal was to eveluat string containing only true, false and logic operators. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 14, 2013 Share Posted February 14, 2013 That's correct, eval simply executes code it does not automatically return a value unless the evaluated code contains a return statement. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now