SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: is_null()

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    is_null()

    The manual says is_null returns a TRUE/FALSE.

    http://php.net/manual/en/function.is-null.php

    Why does this return a 1? I expected "TRUE".

    PHP Code:
    $_SESSION['logged_on'] = null;

    if (
    is_null($_SESSION['logged_on'])) {
      echo 
    is_null($_SESSION['logged_on']) . '<br/>';
    }
    exit; 

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,266
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    When you echo a boolean, it is implicitly typecast to a string, and PHP decided that true would convert to "1" and false to "".

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jeff Mott.

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    $b=false;

    var_dump($b);

    // boolean false 
    Use var_dump() to test expectations - shows value and type.

  5. #5
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,830
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    @nichemtktg

    Maybe this will help:

    http://deformedweb.co.uk/php_variable_tests.php
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks Cups and John_Betong


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •