473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Double check of variables.

Hello,

In some examples of a PHP implementation I saw the following:
if ( isset(x) and x==12)
I do not understand what for before to check whether some variable has
some value one need to check whether this variable is set. If the
second condition is true than the first one is also true, isn't?

Jul 24 '05 #1
3 1568

<op*********@yahoo.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hello,

In some examples of a PHP implementation I saw the following:
if ( isset(x) and x==12)
I do not understand what for before to check whether some variable has
some value one need to check whether this variable is set. If the
second condition is true than the first one is also true, isn't?


The order of checking here is the same as in C, C++, Java, etc. It checks
the first condition. If that fails, it does NOT check the second condition.
If you were to check the second condtion only, then it might cause an error
condition that produces undesirable results. In the case you cite, that
probably won't happen. It is generally used best when you might have a
pointer off into never-never land. So, it is good programming practice to
alway be CERTAIN that your variable being tested actually exists before
testing its value.

Shelly
Jul 24 '05 #2
The reason for isset check is that without it, if x isn't set, PHP will
generate a warning on some systems.

Jul 24 '05 #3
op*********@yahoo.com wrote:
Hello,

In some examples of a PHP implementation I saw the following:
if ( isset(x) and x==12)
I do not understand what for before to check whether some variable has
some value one need to check whether this variable is set. If the
second condition is true than the first one is also true, isn't?


Yes, but the problem occurs when the variable *isn't* set.

<?php
//$x = 12;
if ($x == 12) {
echo 'The variable $x is equal to 12.';
}
?>

The above code will give you the following:
"Notice: Undefined variable: x in [file] on line [line]"

It's not fatal, so the script will keep going, but it's generally not a
good idea to just ignore things like that.

- Ryan
Jul 24 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Display Name | last post by:
the customer I'm developing a site for uses a canned form-parsing page that allows her to have an email subscription opt-in page add emails to a list she can manage using a link that you point your...
13
by: Joey Martin | last post by:
I'm sure this has to be a simple fix. I just cannot figure it out. To resolve the typical apostrope issue, I have the acarriername = Replace(txtcarriername.text, "'", "''") My problem is that...
8
by: Philipp | last post by:
Hello, I would like to print (cout) the binary representation of a double. ie the values of the bytes 1-8. A typical output would be something like (in hex) ff af 12 d3 ab 9f 3c 00 Is there a...
11
by: John | last post by:
Hi, I encountered a strange problem while debugging C code for a Windows-based application in LabWindows CVI V5.5, which led me to write the test code below. I tried this code with a different...
44
by: Daniel | last post by:
I am grappling with the idea of double.Epsilon. I have written the following test: public void FuzzyDivisionTest() { double a = 0.33333d; double b = 1d / 3d; Assert.IsFalse(a == b,...
3
by: Andrew Murray | last post by:
Is it possible to compare a double with a float in c# without casting to one of the types first? It appears you cannot... float num = 1.545f; double dnum = 1.545; if (dnum == num)
5
by: Peter Pippinger | last post by:
Hello NG, i need to calculate the modulus with double precisson typed variables. this works well with integers: w1 = w1 % 360; but what do i have to do if i want to use w1 as double? ...
1
by: redpayne | last post by:
Okay, I finally got this program to run according to what the book had us build it as. Now prof wants case 2 and case 3 to prompt again for input, check input to see if it is the correct type, then...
29
by: Virtual_X | last post by:
As in IEEE754 double consist of sign bit 11 bits for exponent 52 bits for fraction i write this code to print double parts as it explained in ieee754 i want to know if the code contain any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.