variable with NULL value

variable with NULL value

am 03.05.2007 17:22:14 von Oskar

Hi,

one more question.

Why the variable, that contains NULL value appears to be not set. When
you try to echo it the php does not produce warning about using
undefined variable.

//$connection contains database connection handler
$result=mysql_query("select NULL as value",$connection);
$tmp=mysql_fetch_array($result);
$foo=$tmp["value"];
if (!isset($foo)) echo("\$foo is not set but does not produce warning
-$foo-");

OKi98

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: variable with NULL value

am 03.05.2007 21:47:00 von James Gadrow

OKi98 wrote:
> Hi,
>
> one more question.
>
> Why the variable, that contains NULL value appears to be not set. When
> you try to echo it the php does not produce warning about using
> undefined variable.
>
> //$connection contains database connection handler
> $result=mysql_query("select NULL as value",$connection);
> $tmp=mysql_fetch_array($result);
> $foo=$tmp["value"];
> if (!isset($foo)) echo("\$foo is not set but does not produce warning
> -$foo-");
>
> OKi98
>
Someone correct me if I'm wrong but it appears that you should be using
if(!isset($tmp["value"]) before assigning to $foo if you want to ensure
that $foo will, indeed, be set.

--
Thanks,

Jim

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: variable with NULL value

am 04.05.2007 02:47:25 von dmagick

James Gadrow wrote:
> OKi98 wrote:
>> Hi,
>>
>> one more question.
>>
>> Why the variable, that contains NULL value appears to be not set. When
>> you try to echo it the php does not produce warning about using
>> undefined variable.
>>
>> //$connection contains database connection handler
>> $result=mysql_query("select NULL as value",$connection);
>> $tmp=mysql_fetch_array($result);
>> $foo=$tmp["value"];
>> if (!isset($foo)) echo("\$foo is not set but does not produce warning
>> -$foo-");
>>
>> OKi98
>>
> Someone correct me if I'm wrong but it appears that you should be using
> if(!isset($tmp["value"]) before assigning to $foo if you want to ensure
> that $foo will, indeed, be set.

Yeh - you need to check before you do the assignment.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: variable with NULL value

am 04.05.2007 16:55:13 von M.Ford

T24gMDMgTWF5IDIwMDcgMTY6MjIsIE9LaTk4IHdyb3RlOg0KDQo+IEhpLA0K
PiANCj4gb25lIG1vcmUgcXVlc3Rpb24uDQo+IA0KPiBXaHkgdGhlIHZhcmlh
YmxlLCB0aGF0IGNvbnRhaW5zIE5VTEwgdmFsdWUgYXBwZWFycyB0byBiZSBu
b3QNCj4gc2V0Lg0KDQpVbW1tbSAtLSBiZWNhdXNlIHRoYXQncyBob3cgaXQn
cyBkZWZpbmVkPz8gIChodHRwOi8vcGhwLm5ldC9pc3NldCkNCg0KQ2hlZXJz
IQ0KDQpNaWtlDQoNCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQ0KTWlrZSBG
b3JkLCAgRWxlY3Ryb25pYyBJbmZvcm1hdGlvbiBTZXJ2aWNlcyBBZHZpc2Vy
LA0KSkcxMjUsIFRoZSBIZWFkaW5nbGV5IExpYnJhcnksDQpKYW1lcyBHcmFo
YW0gQnVpbGRpbmcsIExlZWRzIE1ldHJvcG9saXRhbiBVbml2ZXJzaXR5LA0K
SGVhZGluZ2xleSBDYW1wdXMsIExFRURTLCAgTFM2IDNRUywgIFVuaXRlZCBL
aW5nZG9tDQpFbWFpbDogbS5mb3JkQGxlZWRzbWV0LmFjLnVrDQpUZWw6ICs0
NCAxMTMgODEyIDQ3MzAgICAgICAgICAgRmF4OiAgKzQ0IDExMyA4MTIgMzIx
MSANCgoKVG8gdmlldyB0aGUgdGVybXMgdW5kZXIgd2hpY2ggdGhpcyBlbWFp
bCBpcyBkaXN0cmlidXRlZCwgcGxlYXNlIGdvIHRvIGh0dHA6Ly9kaXNjbGFp
bWVyLmxlZWRzbWV0LmFjLnVrL2VtYWlsLmh0bQo=