473,563 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1578

<op*********@ya hoo.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.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*********@yah oo.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
3764
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 HTML form to. the actual form-parsing page resides on a server that's uneditable to me since it sits on an inaccessible server. my problem is...
13
2044
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 2 apostrophes are now inserted, instead of one. For example if someone types in IT'S NICE, when it is displayed in the input text box later (to...
8
3207
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 function which does this or anything approaching? I read that on win32 the representation of 8byte double is byte1 byte2 byte3 ...
11
2371
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 compiler and got the same erroneous result on two different PCs (with OS Win98 & Win98SE), so it appears to be a problem with ANSI C. I thought that...
44
16291
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, "Built-in == operator should not be
3
9876
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
92247
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? Thanks a lot!
1
7410
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 display a "correct" message if is correct. So, If you choose 2 from the original pane, you would be prompted to enter an integer. The program would...
29
2935
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 bug , i am still c++ beginner
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.