-5

Possible Duplicate:
php variable as conditional assignment

I am trying to concatenate a conditional assignment through php variables like this

$cndtnal='&& $x==4';

if($y==5 eval($cndtnal)){
   print 'Hello World';
}

But I am getting a Parse error: syntax error, unexpected $end in : eval()'d code on line 1.

I have tried too :

$cndtnal='&& $x==4';

if (eval('$y==5'.$cndtnal)){
       print 'Hello World';
    }

But I get the same error.

Thanks.

2
  • 1
    Your last question about this has an answer -- does that answer not work? Commented Aug 29, 2012 at 4:46
  • 1
    Hi rdlowrey, no it didn't work Commented Aug 29, 2012 at 5:08

1 Answer 1

0

You're missing return and a semicolon.

But really, you should avoid eval.

<?php
$foo = 1;
$bar = 2;
$test = ' && $bar == 2';
if(eval('return $foo == 1' . $test . ';')) {
    echo "That horribly eval()'d code worked!";
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.