FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » evaluating a null value in an array
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
evaluating a null value in an array [message #173825] Sat, 07 May 2011 11:27 Go to next message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma: 0
Senior Member
I have an array of values, one of which might be null.

This statement fails
if ( ($dos <= $insInfo[3]) or($dos == '0000-00-00'))

with the error:
Notice: Undefined offset: 3 in
/var/www/MP2010-v2/classes/cDollar.php on line 237

when $insInfo[3] is NULL.

I figured I could shortcut the evaluation with:

if ( ( is_null($insInfo[3])) or($dos <= $insInfo[3]) or($dos ==
'0000-00-00'))

but I get the same error.

I sure would appreciate:
knowing why I get the error, and
a suggestion on how to evaluate this value.

bill
Re: evaluating a null value in an array [message #173827 is a reply to message #173825] Sat, 07 May 2011 11:36 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/7/2011 7:27 AM, bill wrote:
> I have an array of values, one of which might be null.
>
> This statement fails
> if ( ($dos <= $insInfo[3]) or($dos == '0000-00-00'))
>
> with the error:
> Notice: Undefined offset: 3 in /var/www/MP2010-v2/classes/cDollar.php on
> line 237
>
> when $insInfo[3] is NULL.
>
> I figured I could shortcut the evaluation with:
>
> if ( ( is_null($insInfo[3])) or($dos <= $insInfo[3]) or($dos ==
> '0000-00-00'))
>
> but I get the same error.
>
> I sure would appreciate:
> knowing why I get the error, and
> a suggestion on how to evaluate this value.
>
> bill

Is it null, or is it not set? There is a difference!

Try isset() instead of is_null().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: evaluating a null value in an array [message #173832 is a reply to message #173825] Sat, 07 May 2011 15:30 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Sat, 07 May 2011 07:27:21 -0400, bill wrote:

> a suggestion on how to evaluate this value.

if (
!(isset($insInfo[3])) // $insInfo3 not defined
|| (is__null($insInfo[3])) // $insInfo3 defined and null
|| ($dos <= $insInfo[3]) // $insInfo3 > $dos
|| ($dos == '0000-00-00') // $dos null date
)

Rgds

Denis McMahon
Re: evaluating a null value in an array [message #173833 is a reply to message #173832] Sat, 07 May 2011 16:34 Go to previous messageGo to next message
Gregor Kofler is currently offline  Gregor Kofler
Messages: 69
Registered: September 2010
Karma: 0
Member
Am 2011-05-07 17:30, Denis McMahon meinte:
> On Sat, 07 May 2011 07:27:21 -0400, bill wrote:
>
>> a suggestion on how to evaluate this value.
>
> if (
> !(isset($insInfo[3])) // $insInfo3 not defined
> || (is__null($insInfo[3])) // $insInfo3 defined and null

Not necessary.

isset() also returns false when the tested variable is set to NULL [1].

$bar = NULL;
var_dump(isset($foo)); // FALSE
var_dump(isset($bar)); // FALSE

Gregor


[1]
http://php.net/manual/de/function.isset.php

--
http://vxweb.net
Re: evaluating a null value in an array [message #173834 is a reply to message #173827] Sat, 07 May 2011 16:35 Go to previous messageGo to next message
Gregor Kofler is currently offline  Gregor Kofler
Messages: 69
Registered: September 2010
Karma: 0
Member
Am 2011-05-07 13:36, Jerry Stuckle meinte:
> On 5/7/2011 7:27 AM, bill wrote:
>> I have an array of values, one of which might be null.
>>
>> This statement fails
>> if ( ($dos <= $insInfo[3]) or($dos == '0000-00-00'))
>>
>> with the error:
>> Notice: Undefined offset: 3 in /var/www/MP2010-v2/classes/cDollar.php on
>> line 237
>>
>> when $insInfo[3] is NULL.
>>
>> I figured I could shortcut the evaluation with:
>>
>> if ( ( is_null($insInfo[3])) or($dos <= $insInfo[3]) or($dos ==
>> '0000-00-00'))
>>
>> but I get the same error.
>>
>> I sure would appreciate:
>> knowing why I get the error, and
>> a suggestion on how to evaluate this value.
>>
>> bill
>
> Is it null, or is it not set? There is a difference!

Which isset() won't spot.

http://php.net/manual/de/function.isset.php


Gregor


--
http://vxweb.net
Re: evaluating a null value in an array [message #173836 is a reply to message #173827] Sat, 07 May 2011 17:50 Go to previous messageGo to next message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma: 0
Senior Member
On 5/7/2011 7:36 AM, Jerry Stuckle wrote:
> On 5/7/2011 7:27 AM, bill wrote:
>> I have an array of values, one of which might be null.
>>
>> This statement fails
>> if ( ($dos <= $insInfo[3]) or($dos == '0000-00-00'))
>>
>> with the error:
>> Notice: Undefined offset: 3 in
>> /var/www/MP2010-v2/classes/cDollar.php on
>> line 237
>>
>> when $insInfo[3] is NULL.
>>
>> I figured I could shortcut the evaluation with:
>>
>> if ( ( is_null($insInfo[3])) or($dos <= $insInfo[3]) or($dos ==
>> '0000-00-00'))
>>
>> but I get the same error.
>>
>> I sure would appreciate:
>> knowing why I get the error, and
>> a suggestion on how to evaluate this value.
>>
>> bill
>
> Is it null, or is it not set? There is a difference!
>
> Try isset() instead of is_null().

Exactly, when I use isset it does not error.
Thanks.

bill
Re: evaluating a null value in an array [message #173837 is a reply to message #173834] Sat, 07 May 2011 23:46 Go to previous messageGo to next message
dougatmilmacdotcom is currently offline  dougatmilmacdotcom
Messages: 24
Registered: May 2011
Karma: 0
Junior Member
In article <iq3scb$gre$2(at)dont-email(dot)me>, Gregor Kofler <usenet(at)gregorkofler(dot)com> wrote:
> Am 2011-05-07 13:36, Jerry Stuckle meinte:
>> On 5/7/2011 7:27 AM, bill wrote:
>>> I have an array of values, one of which might be null.
>>>
>>> This statement fails
>>> if ( ($dos <= $insInfo[3]) or($dos == '0000-00-00'))
>>>
>>> with the error:
>>> Notice: Undefined offset: 3 in /var/www/MP2010-v2/classes/cDollar.php on
>>> line 237
>>>
>>> when $insInfo[3] is NULL.
>>>
>>> I figured I could shortcut the evaluation with:
>>>
>>> if ( ( is_null($insInfo[3])) or($dos <= $insInfo[3]) or($dos ==
>>> '0000-00-00'))
>>>
>>> but I get the same error.
>>>
>>> I sure would appreciate:
>>> knowing why I get the error, and
>>> a suggestion on how to evaluate this value.
>>>
>>> bill
>>
>> Is it null, or is it not set? There is a difference!
>
> Which isset() won't spot.

Nonetheless, isset() is the right function to use here. is_null($x) fails if
$x is not set; isset($x) does not.
Re: evaluating a null value in an array [message #173841 is a reply to message #173834] Sun, 08 May 2011 11:56 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Gregor Kofler wrote:

> http://php.net/manual/de/function.isset.php

In this international newsgroup (and maybe elsewhere), it is probably better
to suggest

<http://php.net/isset>

This takes advantage of several features of the PHP.net Web site:

- The mirror will be chosen according to the visitor's geographic
location (or their preferences), which should provide them with the
fastest/most desirable viewing experience;

- The language will be chosen according to visitor preferences (cookies)
(although it must be said that the English version is apparently the
most accurate and up-to-date one);

- Whenever the documentation structure changes, relevant information
can still be found; either through implicit redirection, or through
the search results being displayed for parts of the documentation
where redirection is not implemented.

Therefore, I have found this bookmarklet useful:

http://php.net/%s


Regards,

PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
Re: evaluating a null value in an array [message #173843 is a reply to message #173841] Sun, 08 May 2011 18:18 Go to previous message
Gregor Kofler is currently offline  Gregor Kofler
Messages: 69
Registered: September 2010
Karma: 0
Member
Am 2011-05-08 13:56, Thomas 'PointedEars' Lahn meinte:
> Gregor Kofler wrote:
>
>> http://php.net/manual/de/function.isset.php
>
> In this international newsgroup (and maybe elsewhere), it is probably better
> to suggest
>
> <http://php.net/isset>

Indeed. I normally both use and suggest the English version of the
manual. Googling for a quick link gave me the German version, and I
didn't pay enough attention.

Gregor
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Design minisite with minisite master tutorial
Next Topic: getting only the temperature & general weather condition
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 02:12:59 GMT 2024

Total time taken to generate the page: 0.06609 seconds