Jump to content

Randomish Question on if's


Ryokotsusai

Recommended Posts

I see things used in a lot of scripts:

if(!isset(this)) {do this} else {or do this}

 

and my question is, Is using not set, or not equal to better, or does it have some advantage over using just isset() or ==?

 

'cause from what i have seen everyone seems to go towards "is not..."

Link to comment
Share on other sites

I dont understand why it matters. It depends on the situation. Sometimes a variable will be given different values depending on parameters and sometimes is only set if a form was submitted. So there is no advantage in using anyone of those. THERE is an advantage in using it when you need to.

 

common sense.

 

I'm a noob.

Link to comment
Share on other sites

isset wasn't the question  :D i was talking about th preference ppl seem to have of using "!" in if statements

 

@filmgod

 

i agree that in a lot of situations it does make sense, but then again in just as many there is an "else" statment, that was always a part of it, which negates the need for the "!" as it does something anyway and would work the same the other way

 

ie:

if($this != $that) {echo "They are not the same."; } else {echo "They are the same.";}

 

does the same thing as:

 

if($this == $that) {echo "They are the same.";} else {echo "They are not the same.";}  

 

right?

 

yet out of all the examples i have read, post i have seen, and scripts I have torn apart, 90% of the time the person who wrote it used != or !isset() with an else.  So if it has no real advantage in a situation where there is an 'else' are we just drawn toward a negative?

Link to comment
Share on other sites

isset wasn't the question  :D i was talking about th preference ppl seem to have of using "!" in if statements

 

@filmgod

 

i agree that in a lot of situations it does make sense, but then again in just as many there is an "else" statment, that was always a part of it, which negates the need for the "!" as it does something anyway and would work the same the other way

 

ie:

if($this != $that) {echo "They are not the same."; } else {echo "They are the same.";}

 

does the same thing as:

 

if($this == $that) {echo "They are the same.";} else {echo "They are not the same.";}  

 

right?

 

yet out of all the examples i have read, post i have seen, and scripts I have torn apart, 90% of the time the person who wrote it used != or !isset() with an else.  So if it has no real advantage in a situation where there is an 'else' are we just drawn toward a negative?

 

YOu need to code php in such a way that the less common action will be the if. You should code, if (form was submitted) { then do this }else { do this}

 

Not the other way around for various reasons. Let's say the code somehow got messed up or something, then the default (else) would be exectuted and thus should be the default or more common action.

 

Awesome thefilmgod example:

 

if ($authorized != true) {

 

do not give authorizaton

 

}

else {

 

give authorization

 

}

Althought it should always work the else statement to give authorization as the last end option is pretty stupid logically.

Link to comment
Share on other sites

The NOT (!) operator will give u more control if the situation requests it and most of the time make your code a bit cleaner. For example in a boolean variable: instead of "if($var == false)" u use "if(!$var)". It all depends of the situation and how u're used to coding. I have a practice of using it a lot of time and i like that way.

Link to comment
Share on other sites

hmm I think this is what hes asking and I would like to know the anser...

 

in the following, which is the best? fastest? mose secure?

 

if (A!=1)
if (!A=1)
if (A is not 1)
if (A does not equal 1)

 

Cause on my servery they all work, and my tries to time them were completely random.

Link to comment
Share on other sites

well how I like to code is have whichever way will have the MAIN stuff at the top and the error trapping below.

 

IE: (Only wanting prodigy2k7 to visit)

 

if ($name == prodigy2k7) {

  do this;

  also this;

  and this;

  and this;

  more of this;

  and this;

}

else {

  echo "You are not allowed."

}

 

OR (Wanting anyone EXCEPT prodigy2k7 to visit)

 

if ($name != prodigy2k7) {

  do this;

  also this;

  and this;

  and this;

  more of this;

  and this;

}

else {

  echo "You are not allowed."

}

 

See what I mean? It really depends on what your doing.

I like to have most of the code at the top, so therefore I do whatever is necesarry at the top using == or != so it really depends on the person and what your doing.

 

 

No there is no difference. It is a language that you are coding for yourself. Look at Shakespeare, he writes how he wants to. You can code how you want to, how you best understand it.

 

Enjoy :)

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.