Strange if statement

This is a discussion on Strange if statement within the PHP Language forums, part of the PHP Programming Forums category; if ($result) $total = $result->RecordCount(); Is this if statement purely looking for the prescence of the variable of $result ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-13-2005
Phil Latio
 
Posts: n/a
Default Strange if statement

if ($result)
$total = $result->RecordCount();

Is this if statement purely looking for the prescence of the variable of
$result before executing?

Cheers

Phil








Reply With Quote
  #2 (permalink)  
Old 05-13-2005
Oli Filth
 
Posts: n/a
Default Re: Strange if statement

Phil Latio wrote:
> if ($result)
> $total = $result->RecordCount();
>
> Is this if statement purely looking for the prescence of the variable

of
> $result before executing?
>


No, it's checking whether the value of $result evaluates to boolean
TRUE.

See http://www.php.net/manual/types.comparisons.php

--
Oli

Reply With Quote
  #3 (permalink)  
Old 05-13-2005
dracolytch
 
Posts: n/a
Default Re: Strange if statement

Basically it's making sure that $result is not the following values:

0
''
FALSE
(null)

Databases have a habit of returning FALSE or (null) when they encounter
an error. Essentially, this is a check to see if the query executed
properly.

~D

Reply With Quote
  #4 (permalink)  
Old 05-14-2005
Tim Roberts
 
Posts: n/a
Default Re: Strange if statement

"Phil Latio" <phil.latio@f-in-stupid.co.uk> wrote:
>
>if ($result)
>$total = $result->RecordCount();
>
>Is this if statement purely looking for the prescence of the variable of
>$result before executing?


Presence, maybe, or perhaps a "null" error result from some API.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:21 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0