try - catch ore something like this




I have a litte problem.

In my code I have to try, if this code works:

eval( "\$such_uID = array_intersect ($str);" );

if it doesn't works, this code should be done:

eval("\$such_uID =\"$str\";");

how can I do this? The problem is, that I get a error back, when the first code doesn't work.
Is there in PHP somethin like try, catch?

Thank you!
As far as I found, you still need to use variable concatenation within evals in php even though the equation has to be encased in double quotes.

eval("\$such_uID = array_intersect(" .$str. ");");

the on-fail (false / not array return) shouldn't need evaling

$such_uID = (is_array($such_uID)) ? $such_uID : $str;

I assume $str is a string of the order
'$arg1,$arg2' or
'array("a","b"), array("b","c")'
well...these things I know.

The eval() function is going without problems.

My Problem is, that in the $str Variable are arrays, one, two or more, this I don't know.

That's the Problem, I have to know, how much arrays are in the variable $str, if there is one, or more. If there is only one, this code should be done:

eval("\$such_uID =\"$str\";");

otherwise this one:

eval( "\$such_uID = array_intersect ($str);" );

and i thought, the simpliest solution would be, if i would look, if it's possible to do the second code, (if there aren't two arrays in it, there is not a False, nor a zero, there is a error message).

That's why I thought, try/catch would be great, but I think, there isn't something like this in PHP... :(