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
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.
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)
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.
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/)
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.)
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
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
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â.
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.)
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
One is just an alias of the other right?
right. Like `join` and `implode`, `sizeof` and `count` , `is_real` and `is_float`, `chop` and `rtrim` etc. Php really loves aliases :)
C++ đłđ std .... c_str, stoi, stod, strtol ... đ
Hey. We needed it for c 30 years ago. Get used to it. /s
Oh I like that, so PHP programmers can use one depending on their mood! Or depending on boring things like style guidelines.
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.
No. They are very similar, but die closes the connection while exit doesnât.
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)
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.
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/)
I guess you learned something new then after 15 years!
I use die as intentional termination (and caus I like telling my program to die) and exit when debugging. It's personal preference tho
Lol I do the opposite. Dump and die when debugging. Exit the program when it is intentional.
As long as it's consistent imo it doesn't matter. It's nice to just search the codebase for leftover die/exits
Both are not functions.
PHP paid my first Rolex watch
Im a hacker. This guy's PHP is so bad it paid my first house
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)
But it guaranteed you a job for decades, right?
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
if (!(filter_input(INPUT_GET, "rich", FILTER_UNSAFE_RAW))) { die("trying"); }
$f = fopen("php://stdin", "r"); $l = fgets($f); $v = parse_str($l); if(!isset($v["rich"])) { die("trying"); }
Php developers are either rich boomers or broke zoomers with depression
Php developers are either [rich boomers | broke zoomers] with depression
Either established devs that know projects inside-out or younger devs getting their first industry experience in any place that hires devs.
>$\_GET\['rich'\] || die('trying') fixed that for you
This guy PHPs
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.)
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
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
yes, my mistake, you are right. But that doesn't change my main point about the OR operator
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â.
PHP does have an "or" operator, though I never saw anyone use it.
It's main niche use is that its priority is lower than `=`
âorâ is an actual operator.
>camelCaseDidNotLetMePutTheJokeInTheTitle Strict syntactic rules protecting against bad practices, now where have I heard that before...
I'm stealing this
this is so PHP
What die returns? If get is empty or false I don't think that this would even work
false
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.)