evaluating a null value in an array [message #173825] |
Sat, 07 May 2011 11:27 |
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 |
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 |
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 #173834 is a reply to message #173827] |
Sat, 07 May 2011 16:35 |
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 |
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 |
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 |
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.)
|
|
|
|