#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,670
    Rep Power
    171

    =false Vs. unset


    Hi whats the difference? They both seem to destroy the variables value:
    PHP Code:
    unset($_SESSION['name']); 
    PHP Code:
     $_SESSION['name'] = false
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    Assigning a new value to a variable always "destroys" the value that's currently stored in it. The difference is that unset destroys the variable itself, and assigning false to a variable just change's the variables value to false.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,670
    Rep Power
    171
    Originally Posted by E-Oreo
    Assigning a new value to a variable always "destroys" the value that's currently stored in it. The difference is that unset destroys the variable itself, and assigning false to a variable just change's the variables value to false.
    Are oyu saying false is value?
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    Yes false is certainly a value.

    The only value that could arguably not be considered to be a value is null. However, there is still a difference between a variable that has a value of null and a variable that is not defined.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  8. #5
  9. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,670
    Rep Power
    171
    Thanks
  10. #6
  11. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123

    my 2c worth


    PHP Code:
    //
    $foo 'a';

    var_dump($foo);

    unset(
    $foo);

    var_dump($foo);

    if(
    $foo == null) {
        echo 
    "foo is null<br />\n";
    } else {
        echo 
    "foo is NOT null<br />\n";
    }

    if(
    $foo === null) {
        echo 
    "foo is null<br />\n";
    } else {
        echo 
    "foo is NOT null<br />\n";
    }

    if(
    $foo == false) {
        echo 
    "foo is false<br />\n";
    } else {
        echo 
    "foo is NOT false<br />\n";
    }

    if(
    $foo === false) {
        echo 
    "foo is false<br />\n";
    } else {
        echo 
    "foo is NOT false<br />\n";
    }


    if(isset(
    $foo)) {
        echo 
    "foo is set<br />\n";
    } else {
        echo 
    "foo is NOT set<br />\n";
    }


    $bar 'b';

    var_dump($bar);

    $bar false;

    var_dump($bar);

    if(
    $bar == false) {
        echo 
    "bar is false<br />\n";
    } else {
        echo 
    "bar is NOT false<br />\n";
    }

    if(
    $bar === false) {
        echo 
    "bar is false<br />\n";
    } else {
        echo 
    "bar is NOT false<br />\n";
    }

    if(
    $bar == null) {
        echo 
    "bar is null<br />\n";
    } else {
        echo 
    "bar is NOT null<br />\n";
    }

    if(
    $bar === null) {
        echo 
    "bar is null<br />\n";
    } else {
        echo 
    "bar is NOT null<br />\n";
    }

    if(isset(
    $bar)) {
        echo 
    "bar is set<br />\n";
    } else {
        echo 
    "bar is NOT set<br />\n";

    Code:
    string 'a' (length=1)
    
    null
    
    foo is null
    foo is null
    foo is false
    foo is NOT false
    foo is NOT set
    
    string 'b' (length=1)
    
    boolean false
    
    bar is false
    bar is false
    bar is null
    bar is NOT null
    bar is set
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]

IMN logo majestic logo threadwatch logo seochat tools logo