try - catch ore something like this

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Brumbrum
New php-forum User
New php-forum User
Posts: 9
Joined: Wed Jul 16, 2003 3:31 am

try - catch ore something like this

Postby Brumbrum » Thu Jul 17, 2003 12:53 am

Hi!

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:

Code: Select all

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!

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Thu Jul 17, 2003 2:34 am

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")'

Brumbrum
New php-forum User
New php-forum User
Posts: 9
Joined: Wed Jul 16, 2003 3:31 am

Postby Brumbrum » Thu Jul 17, 2003 3:06 am

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:

Code: Select all

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


otherwise this one:

Code: Select all

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... :(


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests