Syphon Posted October 20, 2007 Share Posted October 20, 2007 Is it possible for Ternary statements to handle conditions like the one below? (is_numeric($_REQUEST["UserID"])) ? true : header('Location: users.php'); exit ; Can exit be executed after the header call and still only be called within the false condition scope? Quote Link to comment https://forums.phpfreaks.com/topic/74076-solved-simple-ternary-conditionals/ Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Thus another reason why I try to advise against shorthand, and or the ternary operator. I have heard some rumor's it can be faster, however it's * ugly * hard to read * Hard to understand to the average programmer * messy. Quote Link to comment https://forums.phpfreaks.com/topic/74076-solved-simple-ternary-conditionals/#findComment-373965 Share on other sites More sharing options...
Barand Posted October 20, 2007 Share Posted October 20, 2007 Can't use the ternary like that. Why not use if (!is_numeric($_REQUEST["UserID"])) { header('Location: users.php'); exit ; } Quote Link to comment https://forums.phpfreaks.com/topic/74076-solved-simple-ternary-conditionals/#findComment-374030 Share on other sites More sharing options...
Syphon Posted October 20, 2007 Author Share Posted October 20, 2007 Can't use the ternary like that. Why not use if (!is_numeric($_REQUEST["UserID"])) { header('Location: users.php'); exit ; } I figured as much. That's how I do handle redirects for the moment, but I was curious if Ternary could handle multiple lines of execution. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/74076-solved-simple-ternary-conditionals/#findComment-374053 Share on other sites More sharing options...
wildteen88 Posted October 20, 2007 Share Posted October 20, 2007 NO ternary operates are not designed to execute blocks of code. Instead they are designed to do simple bits of processing. Such return a value to a variable. Execute a function based on a condition. Ternary operates are inline conditions. I use ternary operators mainly on client defined variables, eg GET, POST and COOKIE/SESSION. Quote Link to comment https://forums.phpfreaks.com/topic/74076-solved-simple-ternary-conditionals/#findComment-374063 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.