Jump to content

If statement checking


Xtremer360

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.