5

I have string like this,

$condition = "if($test == '1')";

I want to convert it to a conditional expression without using eval().

Is it possible?

7
  • 2
    I don't know other method to evaluate code, but depend on your need, you should be able to have what you are expected with another way (switch, etc..). Can you give us more explanations about the purpose ..? Commented Mar 13, 2013 at 5:23
  • just use $condition = ($test == '1'); the result of the expression will be assigned to $condition... Commented Mar 13, 2013 at 5:23
  • EVIL, oh I mean EVAL(), is your best bet Commented Mar 13, 2013 at 5:25
  • why not to use eval()? Commented Mar 13, 2013 at 5:27
  • For example i have associative array, $adata = array('name' => 'John', 'age' => 21); i have a function that convert that to a string so the output will be like this, $condition = "if($name == 'John' && $age == 21);"; and i want $condition to be converted into a regular conditional expression. Commented Mar 13, 2013 at 5:27

1 Answer 1

1

Take a look at $functionName() or call_user_func($functionName)

More clarification.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.