Strange if statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Latio

    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








  • Oli Filth

    #2
    Re: Strange if statement

    Phil Latio wrote:[color=blue]
    > if ($result)
    > $total = $result->RecordCount( );
    >
    > Is this if statement purely looking for the prescence of the variable[/color]
    of[color=blue]
    > $result before executing?
    >[/color]

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

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

    --
    Oli

    Comment

    • dracolytch

      #3
      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

      Comment

      • Tim Roberts

        #4
        Re: Strange if statement

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

        Presence, maybe, or perhaps a "null" error result from some API.
        --
        - Tim Roberts, timr@probo.com
        Providenza & Boekelheide, Inc.

        Comment

        Working...