#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    454
    Rep Power
    0

    Question Die() Equivalent To Echo Error & Exit() ?


    Php Folks,

    Reading this link, did I understand correctly that you use exit() to halt the script and die() to halt the script after spitting out an error mssg on screen ?

    https://stackoverflow.com/questions/...nd-exit-in-php

    So, the following 1 is equivalent to 2 ?

    1.
    PHP Code:
    if(!1==2) {
    echo 
    "no match";
    exit;

    2.
    PHP Code:
    if(!1==2) die("no match"); 
    Latter seems shortest if you want to halt the script after giving an error. And so, best to use that. Right ?
    And, if you don't want to give error then just use like this. Right ?

    PHP Code:
    if(!1==2) {
    exit;

    The above were rush rough examples.
    Last edited by UniqueIdeaMan; February 3rd, 2018 at 10:12 AM.
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,149
    Rep Power
    4103
    die and exit are the same thing, it even says so in the manual.

    die
    (PHP 4, PHP 5, PHP 7)
    die Equivalent to exit
    Some people use die for error messages and exit for codes but you can use either for both so it's just preference. there is no functional difference.

    Comments on this post

    • UniqueIdeaMan agrees : I agree.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

IMN logo majestic logo threadwatch logo seochat tools logo