Xtremer360 Posted August 28, 2012 Share Posted August 28, 2012 Does this if statement look right to anyone? $user_id should be a a number and the reg key is a string if ((is_numeric($user_id)) && ((isset($registration_key)) && (!empty($registration_key) && (!is_null($registration_key))) && ($registration_key == '')) Quote Link to comment https://forums.phpfreaks.com/topic/267712-if-statement-checking/ Share on other sites More sharing options...
Pikachu2000 Posted August 28, 2012 Share Posted August 28, 2012 Whether it's right or not depends on your validation criteria, which you haven't mentioned. Quote Link to comment https://forums.phpfreaks.com/topic/267712-if-statement-checking/#findComment-1373332 Share on other sites More sharing options...
hakimserwa Posted August 28, 2012 Share Posted August 28, 2012 its wrong. you first tested to see if (!empty($registration_key) which means that if its empty the condition will not be true but at the end you again test to see if it == to nothing which means the condition will be true if it == to nothing. your statement is contradicting. Quote Link to comment https://forums.phpfreaks.com/topic/267712-if-statement-checking/#findComment-1373336 Share on other sites More sharing options...
Xtremer360 Posted August 28, 2012 Author Share Posted August 28, 2012 Here's my full code for the controller. http://pastebin.com/M2PpyMy7 Quote Link to comment https://forums.phpfreaks.com/topic/267712-if-statement-checking/#findComment-1373337 Share on other sites More sharing options...
Christian F. Posted August 28, 2012 Share Posted August 28, 2012 I would recommend you to change your code to "Exit Early". That means checking for error conditions, and if an error is found exit/return from the function. That will help you cut down on the levels of nesting, and make your code a lot easier to read. As it is now, I have to scroll up and down just to see what conditions those error messages belong to. Quote Link to comment https://forums.phpfreaks.com/topic/267712-if-statement-checking/#findComment-1373353 Share on other sites More sharing options...
Xtremer360 Posted August 28, 2012 Author Share Posted August 28, 2012 What do you mean early exit though? What would I insert into my code? Quote Link to comment https://forums.phpfreaks.com/topic/267712-if-statement-checking/#findComment-1373359 Share on other sites More sharing options...
Christian F. Posted August 28, 2012 Share Posted August 28, 2012 You know, you could just have searched for "exit early programming", and found a whole lot of references on the subject. Amongst them, the following Wikipedia article: http://en.wikipedia.org/wiki/Control_flow Searching for "return" in the PHP manual would also have given you quite a few examples. I've even posted a few posts here on PHPfreaks where I've explained how to do this, with code. Quote Link to comment https://forums.phpfreaks.com/topic/267712-if-statement-checking/#findComment-1373375 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.