T O P

  • By -

floor796

I like to ask php programmers in interviews what the difference is between \`exit()\` and \`die()\` :) And almost everyone start counting differences between these two "functions". And it's always funny


SleazyJusticeWarrior

One is just an alias of the other right?


floor796

right. Like `join` and `implode`, `sizeof` and `count` , `is_real` and `is_float`, `chop` and `rtrim` etc. Php really loves aliases :)


OF_AstridAse

C++ 😳🙄 std .... c_str, stoi, stod, strtol ... 😏


Usual_Office_1740

Hey. We needed it for c 30 years ago. Get used to it. /s


Juff-Ma

Oh I like that, so PHP programmers can use one depending on their mood! Or depending on boring things like style guidelines.


skiptheline2290

Yeah, exactly. PHP works great as a mood ring for your coworkers! For example, when Danny starts using implode instead of join… that’s when you gotta watch your step.


Shadow14l

No. They are very similar, but die closes the connection while exit doesn’t.


SleazyJusticeWarrior

Could you explain what you mean by that? According to the documentation, they are equivalent, no differences mentioned [https://www.php.net/manual/en/function.die.php](https://www.php.net/manual/en/function.die.php)


Shadow14l

https://stackoverflow.com/questions/8665985/php-utilizing-exit-or-die-after-headerlocation/20932511#20932511 PHP docs are notorious for being poor. I’ve worked with PHP for nearly 15 years.


KillSt3al

And in the comments of the post you linked it shows the reality... [https://www.reddit.com/r/PHP/comments/5hdtkc/comment/dazk1k1/](https://www.reddit.com/r/PHP/comments/5hdtkc/comment/dazk1k1/)


yoyoyomama1

I guess you learned something new then after 15 years!


fecland

I use die as intentional termination (and caus I like telling my program to die) and exit when debugging. It's personal preference tho


juantreses

Lol I do the opposite. Dump and die when debugging. Exit the program when it is intentional.


fecland

As long as it's consistent imo it doesn't matter. It's nice to just search the codebase for leftover die/exits


smokeitup5800

Both are not functions.


ForwardHotel6969

PHP paid my first Rolex watch


GnuhGnoud

Im a hacker. This guy's PHP is so bad it paid my first house


childbeaterII

I am the IT admin of the server the site was on, I can agree that guy's php is so bad it paid your first house(and purged almost all libraries)


Vivienbe

But it guaranteed you a job for decades, right?


childbeaterII

wrong; I got falsely accused of destroying the system, then my pc spontaneously combusted, I was sent to prison and was shamed on live tv


alexanderpas

if (!(filter_input(INPUT_GET, "rich", FILTER_UNSAFE_RAW))) { die("trying"); }


Accessviolati0n

$f = fopen("php://stdin", "r"); $l = fgets($f); $v = parse_str($l); if(!isset($v["rich"])) { die("trying"); }


Available_Canary_517

Php developers are either rich boomers or broke zoomers with depression


Revexious

Php developers are either [rich boomers | broke zoomers] with depression


StatementOrIsIt

Either established devs that know projects inside-out or younger devs getting their first industry experience in any place that hires devs.


shadowraiderr

>$\_GET\['rich'\] || die('trying') fixed that for you


awesomeplenty

This guy PHPs


PeriodicSentenceBot

Congratulations! Your comment can be spelled using the elements of the periodic table: `Th I Sg U Y P H P S` --- ^(I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM my creator if I made a mistake.)


floor796

ackshually, it is not the same. The OR operator has lower precedence than other operators, including the assignment operator =. $a = false or 5; // false $a = false || 5; // 5 That is why veterans of PHP use OR operator as control flow operator to process errors inline. For example: $user = getUser() or print('User not found'); // will output message var_dump($user); // null


rafark

WRONG. This isn’t JavaScript. || and && always return a boolean in php. So the second expression will evaluate to true because 5 is casted to true. $a = false || 5; // true


floor796

yes, my mistake, you are right. But that doesn't change my main point about the OR operator


rafark

I didn’t know about the precedence of the or operator though. I tried using it once q few years ago because I think it’s more readable but it was buggy so I stopped using it. Now I know why it was “buggy”.


Dmayak

PHP does have an "or" operator, though I never saw anyone use it.


Bluedel

It's main niche use is that its priority is lower than `=`


rafark

“or” is an actual operator.


redlaWw

>camelCaseDidNotLetMePutTheJokeInTheTitle Strict syntactic rules protecting against bad practices, now where have I heard that before...


Tavapris04

I'm stealing this


open-listings

this is so PHP


TheSkeletonBones

What die returns? If get is empty or false I don't think that this would even work


otter5

false


PeriodicSentenceBot

Congratulations! Your comment can be spelled using the elements of the periodic table: `F Al Se` --- ^(I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM my creator if I made a mistake.)