subreddit stringclasses 7
values | author stringlengths 3 20 | id stringlengths 5 7 | content stringlengths 67 30.4k | score int64 0 140k |
|---|---|---|---|---|
loljs | adisbladis | cjm4gh1 | <|soss|><|sot|>Hold your horses! ['10','10','10','10'].map(parseInt) yields [10, NaN, 2, 3]<|eot|><|sost|><|eost|><|sor|>This isn't actually loljs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
The Array.map callback takes three params:
(value, index, array)
Therefore ['10','10','10','10'].map(function(x) {return parseInt(x)}) works the way you probably expected Array.map to work.<|eor|><|eoss|><|endoftext|> | 6 |
loljs | cjwelborn | cjsg2t1 | <|soss|><|sot|>Hold your horses! ['10','10','10','10'].map(parseInt) yields [10, NaN, 2, 3]<|eot|><|sost|><|eost|><|sor|>This isn't actually loljs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
The Array.map callback takes three params:
(value, index, array)
Therefore ['10','10','10','10'].map(function(x) {return parseInt(x)}) works the way you probably expected Array.map to work.<|eor|><|sor|>This is weird at first, but once I read about it, it didn't seem as bad. `parseInt` is being called with `parseInt(value, index)`, when it is expecting `parseInt(value, base)` so the base just keeps going up (with the index). What is "10" in base 2? 2. What about base 3? It's 3.. you see what's happening here. It'll keep doing that until base 37, where it returns NaN (like base 1 does.)
I kinda like that the map callback accepts `(value, index, array)`. I can see it being useful. ...I felt like this needed just a little bit more explanation on the `parseInt` side of things.<|eor|><|eoss|><|endoftext|> | 6 |
loljs | waiting4op2deliver | rzbg6j | <|soss|><|sot|>typeof '' === String<|eot|><|sost|>'string' was what I was looking for...<|eost|><|eoss|><|endoftext|> | 0 |
loljs | igorim | 4crbd1 | <|soss|><|sot|>Math.wtf<|eot|><|sost|>Math.max()
-Infinity
Math.min()
Infinity
Shouldn't that be reverse? <|eost|><|eoss|><|endoftext|> | 0 |
loljs | BaloneyGeek | 4ca7if | <|soss|><|sot|>When is not a number a number?<|eot|><|sost|> $: node
> typeof(NaN)
'number'
><|eost|><|eoss|><|endoftext|> | 0 |
loljs | mort96 | d1gs8jy | <|soss|><|sot|>When is not a number a number?<|eot|><|sost|> $: node
> typeof(NaN)
'number'
><|eost|><|sor|>javascript's number type is a floating point number. NaN is defined by the floating point spec, and is a valid floating point number.<|eor|><|eoss|><|endoftext|> | 11 |
loljs | sethnis | 30tvl7 | <|soss|><|sot|>console.log(.1 + .2)<|eot|><|sost|> > console.log(.1 + .2);
0.30000000000000004
Yes, I know it is due to floating point precision. It's still funny.
<|eost|><|eoss|><|endoftext|> | 0 |
loljs | pxpxy | cpvvylw | <|soss|><|sot|>console.log(.1 + .2)<|eot|><|sost|> > console.log(.1 + .2);
0.30000000000000004
Yes, I know it is due to floating point precision. It's still funny.
<|eost|><|sor|>As much as I hate Js, that's more a "lol programming" thing. Ruby, Python and Java will all give you the exact same result <|eor|><|eoss|><|endoftext|> | 8 |
loljs | cjwelborn | cpvxj60 | <|soss|><|sot|>console.log(.1 + .2)<|eot|><|sost|> > console.log(.1 + .2);
0.30000000000000004
Yes, I know it is due to floating point precision. It's still funny.
<|eost|><|sor|>As much as I hate Js, that's more a "lol programming" thing. Ruby, Python and Java will all give you the exact same result <|eor|><|soopr|>Strange. Seems to be okay with PHP.
https://ideone.com/z7RqPC
<|eoopr|><|sor|>Not really,
Your example:
php > echo "0.1 + 0.2 = " . (0.1 + 0.2) . "\n";
0.1 + 0.2 = 0.3
Let's ask PHP to double check that:
php > echo "0.1 + 0.2 == 0.3 (" . (0.1 + 0.2 == 0.3 ? "true" : "false") . ")\n";
0.1 + 0.2 == 0.3 (false)
It uses IEEE 754 like the others. I'm not really a PHP developer, but it seems that PHP is lying when it says "0.3" the first time.
php > echo "What about this?: " . (0.1 + 0.2 == 0.30000000000000004 ? "Yes" : "No") . "\n";
What about this?: Yes
[...on Ideone.com](https://ideone.com/AWxazx)
<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | callcifer | 3eaw98 | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|eols|><|endoftext|> | 381 |
lolphp | SirClueless | ctdifqp | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>The problem is way worse than you think. Check out what this looks like when printed in hexadecimal: http://3v4l.org/XVTgS
Basically, what is going on is that PHP_INT_MAX is 2^63 - 1. mt_getrandmax() is 2^31 - 1. The way mt_rand() makes a random number when the limit is too large is that it makes a random number in the range [0,2^(31)), then it scales it to be a number in the range [0,MAX-MIN), and finally adds MIN.
So in your case, it scales everything by 2^32 and adds 1. Which is why the numbers are *extremely non-random*. [See my other comment in this thread for a more detailed explanation and some more test scripts that prove this is what is happening.](https://www.reddit.com/r/lolphp/comments/3eaw98/mt_rand1_php_int_max_only_generates_odd_numbers/ctdhxha)<|eor|><|eols|><|endoftext|> | 349 |
lolphp | polish_niceguy | ctd7z8d | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>[I think I know who coded that part](http://i.imgur.com/SbK9oWd.png)<|eor|><|eols|><|endoftext|> | 117 |
lolphp | callcifer | ctd61r5 | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>what the fuck. How do people even find this<|eor|><|soopr|>We just found out about this at work. We were using `mt_rand(1, PHP_INT_MAX)` to generate non-mission-critical numeric identifiers and someone realized none of the numbers were even :)<|eoopr|><|eols|><|endoftext|> | 91 |
lolphp | andreasbeer1981 | cteduc8 | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>well, that's odd...<|eor|><|eols|><|endoftext|> | 83 |
lolphp | callcifer | ctdixmh | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>The problem is way worse than you think. Check out what this looks like when printed in hexadecimal: http://3v4l.org/XVTgS
Basically, what is going on is that PHP_INT_MAX is 2^63 - 1. mt_getrandmax() is 2^31 - 1. The way mt_rand() makes a random number when the limit is too large is that it makes a random number in the range [0,2^(31)), then it scales it to be a number in the range [0,MAX-MIN), and finally adds MIN.
So in your case, it scales everything by 2^32 and adds 1. Which is why the numbers are *extremely non-random*. [See my other comment in this thread for a more detailed explanation and some more test scripts that prove this is what is happening.](https://www.reddit.com/r/lolphp/comments/3eaw98/mt_rand1_php_int_max_only_generates_odd_numbers/ctdhxha)<|eor|><|soopr|>Excellent analysis, thanks. This shows that the mt_rand documentation is extremely misleading and the implementation itself is severely broken. /u/nikic, can anything be done about this?<|eoopr|><|eols|><|endoftext|> | 66 |
lolphp | kinsi55 | ctd60q6 | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>what the fuck. How do people even find this<|eor|><|eols|><|endoftext|> | 52 |
lolphp | heyf00L | ctel63q | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>well, that's odd...<|eor|><|sor|>Dude, that comment, I can't even....<|eor|><|sor|>Can we get a mod 2 remove these comments?<|eor|><|eols|><|endoftext|> | 49 |
lolphp | kinsi55 | ctd651l | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>what the fuck. How do people even find this<|eor|><|soopr|>We just found out about this at work. We were using `mt_rand(1, PHP_INT_MAX)` to generate non-mission-critical numeric identifiers and someone realized none of the numbers were even :)<|eoopr|><|sor|>Just checked the Doc. You should just call `mt_rand()` since `PHP_INT_MAX` is not `mt_getrandmax()`, which is used if you dont define min/max. As a bonus you can see your stuff is broken because all the numbers you get have the same length.
**Edit:** Bonus from doc:
>**Caution**
The distribution of mt_rand() return values is biased towards even numbers on 64-bit builds of PHP when max is beyond 2^32. This is because if max is greater than the value returned by mt_getrandmax(), the output of the random number generator must be scaled up.<|eor|><|eols|><|endoftext|> | 46 |
lolphp | antihexe | ctegfqm | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>The problem is way worse than you think. Check out what this looks like when printed in hexadecimal: http://3v4l.org/XVTgS
Basically, what is going on is that PHP_INT_MAX is 2^63 - 1. mt_getrandmax() is 2^31 - 1. The way mt_rand() makes a random number when the limit is too large is that it makes a random number in the range [0,2^(31)), then it scales it to be a number in the range [0,MAX-MIN), and finally adds MIN.
So in your case, it scales everything by 2^32 and adds 1. Which is why the numbers are *extremely non-random*. [See my other comment in this thread for a more detailed explanation and some more test scripts that prove this is what is happening.](https://www.reddit.com/r/lolphp/comments/3eaw98/mt_rand1_php_int_max_only_generates_odd_numbers/ctdhxha)<|eor|><|sor|>Are the numbers really non random? I would think that the numbers would still be "random" but the entropy of the randomness is limited to the entropy before scaling.
<|eor|><|sor|>They might still be "random," but confined to a reduced number space. As a result, values generated with this RNG are much less random and may be susceptible to brute force.<|eor|><|sor|>That's probably why [the documentation](http://php.net/manual/en/function.mt-rand.php) says "This function does not generate cryptographically secure values, and should not be used for cryptographic purposes."<|eor|><|sor|>All algorithms are "secure" until proven otherwise (which is often trivial to do). This one just also happens to have a bug where mt_rand()%2 will always evaluate to 1.<|eor|><|sor|>>All algorithms are "secure" until proven otherwise
In cryptography we generally go about it the other way. <|eor|><|eols|><|endoftext|> | 45 |
lolphp | TaohRihze | ctefho7 | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>well, that's odd...<|eor|><|sor|>Dude, that comment, I can't even....<|eor|><|eols|><|endoftext|> | 44 |
lolphp | nikic | ctdkk1c | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>The problem is way worse than you think. Check out what this looks like when printed in hexadecimal: http://3v4l.org/XVTgS
Basically, what is going on is that PHP_INT_MAX is 2^63 - 1. mt_getrandmax() is 2^31 - 1. The way mt_rand() makes a random number when the limit is too large is that it makes a random number in the range [0,2^(31)), then it scales it to be a number in the range [0,MAX-MIN), and finally adds MIN.
So in your case, it scales everything by 2^32 and adds 1. Which is why the numbers are *extremely non-random*. [See my other comment in this thread for a more detailed explanation and some more test scripts that prove this is what is happening.](https://www.reddit.com/r/lolphp/comments/3eaw98/mt_rand1_php_int_max_only_generates_odd_numbers/ctdhxha)<|eor|><|soopr|>Excellent analysis, thanks. This shows that the mt_rand documentation is extremely misleading and the implementation itself is severely broken. /u/nikic, can anything be done about this?<|eoopr|><|sor|>I don't think anything can be done about this in PHP 5 -- the results of mt_rand() for a given seed are supposed to be stable. For PHP 7 we might want to make ranges larger than mt_randmax an error condition. If you need something larger than that, use `random_int`.<|eor|><|eols|><|endoftext|> | 44 |
lolphp | polish_niceguy | ctdfewi | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>[deleted]<|eor|><|soopr|>It used to be 100% biased towards [even numbers](https://bugs.php.net/bug.php?id=55519), so something somewhere got changed but it's not any better.<|eoopr|><|sor|>* add 1 to the returned value
* close the "even numbers generated" ticket
* ???
* still no profit<|eor|><|eols|><|endoftext|> | 42 |
lolphp | callcifer | ctd672y | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>what the fuck. How do people even find this<|eor|><|soopr|>We just found out about this at work. We were using `mt_rand(1, PHP_INT_MAX)` to generate non-mission-critical numeric identifiers and someone realized none of the numbers were even :)<|eoopr|><|sor|>Just checked the Doc. You should just call `mt_rand()` since `PHP_INT_MAX` is not `mt_getrandmax()`, which is used if you dont define min/max. As a bonus you can see your stuff is broken because all the numbers you get have the same length.
**Edit:** Bonus from doc:
>**Caution**
The distribution of mt_rand() return values is biased towards even numbers on 64-bit builds of PHP when max is beyond 2^32. This is because if max is greater than the value returned by mt_getrandmax(), the output of the random number generator must be scaled up.<|eor|><|soopr|>Yeah, but the behaviour with PHP_INT_MAX is extremely unintuitive. Why does it generate only odd numbers? Why is `mt_getrandmax()` even a thing? Also, it used to generate only [even numbers](https://bugs.php.net/bug.php?id=55519) at some point?
Classic PHP behaviour, I don't know why I'm surprised...
> Edit: Bonus from doc
Wow, if it's biased towards *even* numbers, why don't we have a single even number in there? :)<|eoopr|><|eols|><|endoftext|> | 40 |
lolphp | NeatG | ctdbjxr | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>what the fuck. How do people even find this<|eor|><|soopr|>We just found out about this at work. We were using `mt_rand(1, PHP_INT_MAX)` to generate non-mission-critical numeric identifiers and someone realized none of the numbers were even :)<|eoopr|><|sor|>Just checked the Doc. You should just call `mt_rand()` since `PHP_INT_MAX` is not `mt_getrandmax()`, which is used if you dont define min/max. As a bonus you can see your stuff is broken because all the numbers you get have the same length.
**Edit:** Bonus from doc:
>**Caution**
The distribution of mt_rand() return values is biased towards even numbers on 64-bit builds of PHP when max is beyond 2^32. This is because if max is greater than the value returned by mt_getrandmax(), the output of the random number generator must be scaled up.<|eor|><|soopr|>Yeah, but the behaviour with PHP_INT_MAX is extremely unintuitive. Why does it generate only odd numbers? Why is `mt_getrandmax()` even a thing? Also, it used to generate only [even numbers](https://bugs.php.net/bug.php?id=55519) at some point?
Classic PHP behaviour, I don't know why I'm surprised...
> Edit: Bonus from doc
Wow, if it's biased towards *even* numbers, why don't we have a single even number in there? :)<|eoopr|><|sor|>mt_getrandmax() makes sense to me. The part that doesn't make sense is why this function doesn't raise an exception or return an error if it's given operands that are outside of what it can work with. That's the lolphp thing about this to me<|eor|><|eols|><|endoftext|> | 39 |
lolphp | tomkul | cteew6y | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>Linux (PHP 5.5.9-1ubuntu4.11):
for ($i = 0; $i<10000000; $i++) {echo mt_rand(1, PHP_INT_MAX)%2==0?'even':'';}
Not even one even!
Windows:
for ($i = 0; $i<10000; $i++) {echo mt_rand(1, PHP_INT_MAX)%2==0?'even':'';}
Many evens!!! :)<|eor|><|eols|><|endoftext|> | 38 |
lolphp | amphetamachine | ctdbpb4 | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>[deleted]<|eor|><|sor|>It's documented, so [it can never change](https://xkcd.com/1172/). It's the PHP way.<|eor|><|eols|><|endoftext|> | 38 |
lolphp | callcifer | ctdejst | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>what the fuck. How do people even find this<|eor|><|soopr|>We just found out about this at work. We were using `mt_rand(1, PHP_INT_MAX)` to generate non-mission-critical numeric identifiers and someone realized none of the numbers were even :)<|eoopr|><|sor|>Just checked the Doc. You should just call `mt_rand()` since `PHP_INT_MAX` is not `mt_getrandmax()`, which is used if you dont define min/max. As a bonus you can see your stuff is broken because all the numbers you get have the same length.
**Edit:** Bonus from doc:
>**Caution**
The distribution of mt_rand() return values is biased towards even numbers on 64-bit builds of PHP when max is beyond 2^32. This is because if max is greater than the value returned by mt_getrandmax(), the output of the random number generator must be scaled up.<|eor|><|soopr|>Yeah, but the behaviour with PHP_INT_MAX is extremely unintuitive. Why does it generate only odd numbers? Why is `mt_getrandmax()` even a thing? Also, it used to generate only [even numbers](https://bugs.php.net/bug.php?id=55519) at some point?
Classic PHP behaviour, I don't know why I'm surprised...
> Edit: Bonus from doc
Wow, if it's biased towards *even* numbers, why don't we have a single even number in there? :)<|eoopr|><|sor|>mt_getrandmax() makes sense to me. The part that doesn't make sense is why this function doesn't raise an exception or return an error if it's given operands that are outside of what it can work with. That's the lolphp thing about this to me<|eor|><|soopr|>> mt_getrandmax() makes sense to me
Personally, if a function (mt_rand) is defined as taking two integer arguments and returning an integer, it should work *correctly* with all valid integers on that platform or, as a last resort, throw an exception.
You are right about the lolphp thing, but PHP's Mersenne Twister implementation uses 32bit integers on *all* platforms, that's the only reason mt_getrandmax() exists, which is a lolphp itself :)<|eoopr|><|eols|><|endoftext|> | 28 |
lolphp | tuananh_org | ctenc1h | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>PHP's logic: it's weird but it's documented, therefore it's not a bug.<|eor|><|eols|><|endoftext|> | 27 |
lolphp | PmMeYourPerkyBCups | cteqhl4 | <|sols|><|sot|>mt_rand(1, PHP_INT_MAX) only generates odd numbers<|eot|><|sol|>http://3v4l.org/dMbat<|eol|><|sor|>[deleted]<|eor|><|sor|>mt_rand(1, PHP_INT_MAX) + mt_rand(0,1);<|eor|><|eols|><|endoftext|> | 27 |
lolphp | phplovesong | mdkvzl | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|eols|><|endoftext|> | 327 |
lolphp | AyrA_ch | gs9ywjg | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|sor|>String splitting is really confusing in PHP though:
- **split**: This splits a string but the delimiter argument is treated as a regex (deprecated and removed)
- **str_split**: Splits a string into an array by a chunk length (defaults to 1) rather than delimiter
- **chunk_split**: Doesn't actually splits a string but inserts a user defined string every n characters.
- **preg_split**: This is what split() is now
- **explode**: This splits a string the way you think split() will but doesn't supports an empty split string like other languages do.<|eor|><|eols|><|endoftext|> | 84 |
lolphp | Regimardyl | gsafb5u | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|sor|>In the very, very first versions of PHP, the function lookup hash table used `strlen` as the hash function. The decision to name it `explode` instead of `split` therefore was for performance reasons, as there were fewer functions with seven-character names as there were functions with five-character names.<|eor|><|eols|><|endoftext|> | 46 |
lolphp | sproingie | gsais1a | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|sor|>In the very, very first versions of PHP, the function lookup hash table used `strlen` as the hash function. The decision to name it `explode` instead of `split` therefore was for performance reasons, as there were fewer functions with seven-character names as there were functions with five-character names.<|eor|><|sor|>And that wasn't a red flag to the designers?<|eor|><|sor|>What "designers"? It was just Rasmus, he didn't know what he was doing, and he admits to that. The folks like Nikita and Ilija who maintain PHP now are much better at it, but they inherited a mess.<|eor|><|eols|><|endoftext|> | 41 |
lolphp | tobiasvl | gsc1k2a | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|sor|>In the very, very first versions of PHP, the function lookup hash table used `strlen` as the hash function. The decision to name it `explode` instead of `split` therefore was for performance reasons, as there were fewer functions with seven-character names as there were functions with five-character names.<|eor|><|sor|>Now this... This is proper lolphp<|eor|><|eols|><|endoftext|> | 39 |
lolphp | AyrA_ch | gsa7w44 | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|sor|>String splitting is really confusing in PHP though:
- **split**: This splits a string but the delimiter argument is treated as a regex (deprecated and removed)
- **str_split**: Splits a string into an array by a chunk length (defaults to 1) rather than delimiter
- **chunk_split**: Doesn't actually splits a string but inserts a user defined string every n characters.
- **preg_split**: This is what split() is now
- **explode**: This splits a string the way you think split() will but doesn't supports an empty split string like other languages do.<|eor|><|sor|>[deleted]<|eor|><|sor|>> And str_split() operates on bytes, so goodbye multibyte characters.
I mean, strings in PHP are essentially just `char*`, hence why `mb_*` functions exist.<|eor|><|eols|><|endoftext|> | 21 |
lolphp | I_LICK_ROBOTS | gsag35j | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|sor|>In the very, very first versions of PHP, the function lookup hash table used `strlen` as the hash function. The decision to name it `explode` instead of `split` therefore was for performance reasons, as there were fewer functions with seven-character names as there were functions with five-character names.<|eor|><|sor|>And that wasn't a red flag to the designers?<|eor|><|eols|><|endoftext|> | 19 |
lolphp | colshrapnel | gs9ymva | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|sor|>Memes about PHP's quirks
Memes about PHP design flaws
Memes when you just hate the language but have no idea what to make a meme about.<|eor|><|eols|><|endoftext|> | 18 |
lolphp | sproingie | gsosl2a | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|sor|>In the very, very first versions of PHP, the function lookup hash table used `strlen` as the hash function. The decision to name it `explode` instead of `split` therefore was for performance reasons, as there were fewer functions with seven-character names as there were functions with five-character names.<|eor|><|sor|>And that wasn't a red flag to the designers?<|eor|><|sor|>What "designers"? It was just Rasmus, he didn't know what he was doing, and he admits to that. The folks like Nikita and Ilija who maintain PHP now are much better at it, but they inherited a mess.<|eor|><|sor|>> he didn't know what he was doing
I don't think that's a good excuse, though. When I wrote my first "interpreter" in C (I really just wanted to evaluate simple arithmetic expressions in my program), I didn't know anything about parsers (or actual hash tables), I just keyed off the first character of the identifier:
switch (s[0]) {
case 'a':
if (strcmp(s, "abs") == 0) {
...
}
break;
...
}
When I had too many functions starting with the same character, I'd just repeat the `switch` with the second character, then the third, etc.
This kind of structure amounts to an inlined trie lookup, so it doesn't matter how many functions there are in total. It will always be fast.
Why would you even think about switching on `strlen(s)`?<|eor|><|sor|>Let's just say I was being a bit euphemistic when describing Rasmus's coding skills. Whichever brand of glue was being sniffed that day sealed the fate of PHP's global namespace for decades.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | sproingie | gsamy5f | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|sor|>In the very, very first versions of PHP, the function lookup hash table used `strlen` as the hash function. The decision to name it `explode` instead of `split` therefore was for performance reasons, as there were fewer functions with seven-character names as there were functions with five-character names.<|eor|><|sor|>And that wasn't a red flag to the designers?<|eor|><|sor|>What "designers"? It was just Rasmus, he didn't know what he was doing, and he admits to that. The folks like Nikita and Ilija who maintain PHP now are much better at it, but they inherited a mess.<|eor|><|sor|>I wasn't sure at what point explode was added to the language. Based on. Some comments above it didn't seem like it was v1<|eor|><|sor|>You're correct, PHP/FI 2.x had only `ereg_*` functions to manipulate strings. Far as I can tell, PHP 1.x is lost to time, so no way to know, but I imagine it wouldn't have been there either. Pretty sure 3.x had it, I used it back in the day.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | barubary | gsoqiym | <|sols|><|sot|>PHP: When naming is thrown out the window<|eot|><|sol|>https://i.redd.it/58agcyondcp61.jpg<|eol|><|sor|>In the very, very first versions of PHP, the function lookup hash table used `strlen` as the hash function. The decision to name it `explode` instead of `split` therefore was for performance reasons, as there were fewer functions with seven-character names as there were functions with five-character names.<|eor|><|sor|>And that wasn't a red flag to the designers?<|eor|><|sor|>What "designers"? It was just Rasmus, he didn't know what he was doing, and he admits to that. The folks like Nikita and Ilija who maintain PHP now are much better at it, but they inherited a mess.<|eor|><|sor|>> he didn't know what he was doing
I don't think that's a good excuse, though. When I wrote my first "interpreter" in C (I really just wanted to evaluate simple arithmetic expressions in my program), I didn't know anything about parsers (or actual hash tables), I just keyed off the first character of the identifier:
switch (s[0]) {
case 'a':
if (strcmp(s, "abs") == 0) {
...
}
break;
...
}
When I had too many functions starting with the same character, I'd just repeat the `switch` with the second character, then the third, etc.
This kind of structure amounts to an inlined trie lookup, so it doesn't matter how many functions there are in total. It will always be fast.
Why would you even think about switching on `strlen(s)`?<|eor|><|sor|>Did you miss the part where Rasmus didn't know what he was doing?
I mean, why are you trying to perceive "I didn't know what I was doing" as some kind "I sort of knew what I was doing"? He didn't.<|eor|><|sor|>Have a look at the code: [screenshot](https://dl.dropboxusercontent.com/s/e8k4n2mx1y5vsa4/Zrzut%20ekranu%202013-12-17%2008.37.01.png), [full source file](https://pastebin.com/iGkMkaex).
He knew what a hash table was, he knew about lexing and parsing, he knew yacc/bison, he knew state machines, he knew about structs, typedefs, function pointers, arrays, he knew mmap(), he knew how to write an Apache module.
This is not "babby's first C code"; this is some fairly advanced stuff.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | ThisIsADogHello | 4em0f9 | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|eols|><|endoftext|> | 279 |
lolphp | Regimardyl | d21arka | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|eols|><|endoftext|> | 77 |
lolphp | squiggleslash | d221bs1 | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>Someone somewhere is looking at this function and thinking to themselves "Hmm, so to find out if my application is running under windows, all I need to do is make the process sleep, and have a forked process interrupt it, and then it can check the return value."
And within a few days, that'll also be the top answer for that particular problem on *Stack Overflow*.
<|eor|><|eols|><|endoftext|> | 48 |
lolphp | masklinn | d21dsd7 | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>I'm greatly disappointed that `time_nanosleep` and `time_sleep_until` both return true on success and false on failure.<|eor|><|eols|><|endoftext|> | 43 |
lolphp | midir | d225kvx | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>\>`int sleep`
\>Returns `FALSE`
Ladies and gentlemen, PHP.<|eor|><|eols|><|endoftext|> | 24 |
lolphp | coredumperror | d21kfs2 | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>> int sleep ( int $seconds )
> Returns zero on success, or FALSE on error.
So if `sleep` returns an int, what the hell is the difference between 0 and FALSE?
edit: for other non-PHP-ites, I did some [googling](http://stackoverflow.com/questions/137487/null-vs-false-vs-0-in-php) and found that while they are different types, they, along with Null, are considered equal by the == operator. I guess I shouldn't be surprised that a language that allows these kinds of type shenanigans would allow a function that's defined as returning an int to return a boolean.<|eor|><|sor|>Yes, this is a very common thing in PHP, sadly. Loads of the standard library functions are extremely thin wrappers around C functions. Basically the only thing the PHP function does is call the C function and then return FALSE on error. Instead of doing something sane, like returning -1 from a function that otherwise returns only positive ints, or throwing an exception, or do *anything* besides returning FALSE, which compares == to 0, which is usually a perfectly good non-error response.<|eor|><|eols|><|endoftext|> | 22 |
lolphp | Drainedsoul | d21od5t | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>> int sleep ( int $seconds )
> Returns zero on success, or FALSE on error.
So if `sleep` returns an int, what the hell is the difference between 0 and FALSE?
edit: for other non-PHP-ites, I did some [googling](http://stackoverflow.com/questions/137487/null-vs-false-vs-0-in-php) and found that while they are different types, they, along with Null, are considered equal by the == operator. I guess I shouldn't be surprised that a language that allows these kinds of type shenanigans would allow a function that's defined as returning an int to return a boolean.<|eor|><|sor|>Yes, this is a very common thing in PHP, sadly. Loads of the standard library functions are extremely thin wrappers around C functions. Basically the only thing the PHP function does is call the C function and then return FALSE on error. Instead of doing something sane, like returning -1 from a function that otherwise returns only positive ints, or throwing an exception, or do *anything* besides returning FALSE, which compares == to 0, which is usually a perfectly good non-error response.<|eor|><|sor|>This is why `===` exists.
I'd posit that `===` should be the default. `==` should be considered code smell.<|eor|><|eols|><|endoftext|> | 21 |
lolphp | z500 | d21e6h1 | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>> int sleep ( int $seconds )
> Returns zero on success, or FALSE on error.
So if `sleep` returns an int, what the hell is the difference between 0 and FALSE?
edit: for other non-PHP-ites, I did some [googling](http://stackoverflow.com/questions/137487/null-vs-false-vs-0-in-php) and found that while they are different types, they, along with Null, are considered equal by the == operator. I guess I shouldn't be surprised that a language that allows these kinds of type shenanigans would allow a function that's defined as returning an int to return a boolean.<|eor|><|eols|><|endoftext|> | 20 |
lolphp | Regimardyl | d21rk2l | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>Is there a reason why you would do anything other than returning nothing on success and throwing an exception on failure?<|eor|><|sor|>> Is there a reason
It's PHP, so there probably is some historic insane reason.<|eor|><|eols|><|endoftext|> | 17 |
lolphp | z500 | d21owqf | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>> int sleep ( int $seconds )
> Returns zero on success, or FALSE on error.
So if `sleep` returns an int, what the hell is the difference between 0 and FALSE?
edit: for other non-PHP-ites, I did some [googling](http://stackoverflow.com/questions/137487/null-vs-false-vs-0-in-php) and found that while they are different types, they, along with Null, are considered equal by the == operator. I guess I shouldn't be surprised that a language that allows these kinds of type shenanigans would allow a function that's defined as returning an int to return a boolean.<|eor|><|sor|>Why are you on lolphp and questioning the internals of php? This sub is primarily intended for people who are painfully aware of PHP's warts. <|eor|><|sor|>> Why are you on lolphp and questioning the internals of php?
Curiosity.
> This sub is primarily intended for people who are painfully aware of PHP's warts.
Oh.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | poizan42 | d26nhnz | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>I'm greatly disappointed that `time_nanosleep` and `time_sleep_until` both return true on success and false on failure.<|eor|><|sor|>[deleted]<|eor|><|sor|>PHP, where consistency is unexpected<|eor|><|eols|><|endoftext|> | 14 |
lolphp | mort96 | d21s655 | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>They could've at least made it "1337".<|eor|><|sor|>> On Windows, this value will always be 192 (the value of the WAIT_IO_COMPLETION constant within the Windows API).
So no, they couldn't really have done that.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | josefx | d22cqax | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>\>`int sleep`
\>Returns `FALSE`
Ladies and gentlemen, PHP.<|eor|><|sor|>Could also be [python](https://docs.python.org/3/library/functions.html#bool):
> The bool class is a subclass of int
This is perfectly acceptable behavior for a scripting language /s<|eor|><|eols|><|endoftext|> | 12 |
lolphp | poizan42 | d26nkxa | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>> int sleep ( int $seconds )
> Returns zero on success, or FALSE on error.
So if `sleep` returns an int, what the hell is the difference between 0 and FALSE?
edit: for other non-PHP-ites, I did some [googling](http://stackoverflow.com/questions/137487/null-vs-false-vs-0-in-php) and found that while they are different types, they, along with Null, are considered equal by the == operator. I guess I shouldn't be surprised that a language that allows these kinds of type shenanigans would allow a function that's defined as returning an int to return a boolean.<|eor|><|sor|>Yes, this is a very common thing in PHP, sadly. Loads of the standard library functions are extremely thin wrappers around C functions. Basically the only thing the PHP function does is call the C function and then return FALSE on error. Instead of doing something sane, like returning -1 from a function that otherwise returns only positive ints, or throwing an exception, or do *anything* besides returning FALSE, which compares == to 0, which is usually a perfectly good non-error response.<|eor|><|sor|>This is why `===` exists.
I'd posit that `===` should be the default. `==` should be considered code smell.<|eor|><|sor|>The "fun" thing is that switch statements always does non-strict comparison.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | mort96 | d2202tp | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>They could've at least made it "1337".<|eor|><|sor|>> On Windows, this value will always be 192 (the value of the WAIT_IO_COMPLETION constant within the Windows API).
So no, they couldn't really have done that.<|eor|><|sor|>[deleted]<|eor|><|sor|>Well yes, they could have arbitrarily made it return 1337 instead of WAIT_IO_COMPLETION, but what I meant was they didn't just choose 192 because it's a pretty number; changing it to another number would ...
and there's where I have issues making my argument. I want to say changing it to another number would make less sense or be less logical, but I'm not entirely sure that's true. The current solution already defies logic.
I suppose I'll just stick to the point that 192 wasn't just arbitrarily picked by the PHP peopole, though that's a weaker argument. I suppose nobody would really care if sleep(), on windows, if interrupted, returned 1337 instead of 192 even though there's theoretically slightly less of a rationale.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | bsander | d22h37q | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>Someone somewhere is looking at this function and thinking to themselves "Hmm, so to find out if my application is running under windows, all I need to do is make the process sleep, and have a forked process interrupt it, and then it can check the return value."
And within a few days, that'll also be the top answer for that particular problem on *Stack Overflow*.
<|eor|><|sor|>https://xkcd.com/1172/<|eor|><|eols|><|endoftext|> | 8 |
lolphp | merreborn | d226bx0 | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>At least PHP doesn't lack consistently inconsistent sleeping functions:
* [`int sleep ( int $seconds )`](http://php.net/manual/en/function.sleep.php)
> Returns zero on success, or `FALSE` on error.
>
> If the call was interrupted by a signal, `sleep()` returns a non-zero value. On Windows, this value will always be *192* (the value of the `WAIT_IO_COMPLETION` constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
* [`void usleep ( int $micro_seconds )`](http://php.net/manual/en/function.usleep.php)
> No value is returned.
* [`mixed time_nanosleep ( int $seconds , int $nanoseconds )`](http://php.net/manual/en/function.time-nanosleep.php)
> Returns `TRUE` on success or `FALSE` on failure.
>
> If the delay was interrupted by a signal, an associative array will be returned with the components:
>
> * *seconds* - number of seconds remaining in the delay
> * *nanoseconds* - number of nanoseconds remaining in the delay
* [`bool time_sleep_until ( float $timestamp )`](http://php.net/manual/en/function.time-sleep-until.php)
> Returns `TRUE` on success or `FALSE` on failure.<|eor|><|sor|>Is there a reason why you would do anything other than returning nothing on success and throwing an exception on failure?<|eor|><|sor|>> Is there a reason
It's PHP, so there probably is some historic insane reason.<|eor|><|sor|>For one: these functions predate exceptions in PHP. And adding exceptions to their behavior when PHP 5 introduced exceptions would have broken backwards compatibility for these functions.
They could have broken backward compatibility, but that could have ended creating a Python 3 sort of situation.
<|eor|><|eols|><|endoftext|> | 8 |
lolphp | xkcd_transcriber | d22h3p0 | <|sols|><|sot|>sleep() returns 0 on success, FALSE on error, or when interrupted by a signal returns number of remaining seconds except on Windows where it returns 192<|eot|><|sol|>http://php.net/manual/en/function.sleep.php<|eol|><|sor|>Someone somewhere is looking at this function and thinking to themselves "Hmm, so to find out if my application is running under windows, all I need to do is make the process sleep, and have a forked process interrupt it, and then it can check the return value."
And within a few days, that'll also be the top answer for that particular problem on *Stack Overflow*.
<|eor|><|sor|>https://xkcd.com/1172/<|eor|><|sor|>[Image](http://imgs.xkcd.com/comics/workflow.png)
[Mobile](https://m.xkcd.com/1172/)
**Title:** Workflow
**Title-text:** There are probably children out there holding down spacebar to stay warm in the winter\! YOUR UPDATE MURDERS CHILDREN\.
[Comic Explanation](https://www.explainxkcd.com/wiki/index.php/1172#Explanation)
**Stats:** This comic has been referenced 671 times, representing 0.6264% of referenced xkcds.
---
^[xkcd.com](https://www.xkcd.com) ^| ^[xkcdsub](https://www.reddit.com/r/xkcd/) ^| ^[Problems/Bugs?](https://www.reddit.com/r/xkcd_transcriber/) ^| ^[Statistics](http://xkcdref.info/statistics/) ^| ^[StopReplying](https://reddit.com/message/compose/?to=xkcd_transcriber&subject=ignore%20me&message=ignore%20me) ^| ^[Delete](https://reddit.com/message/compose/?to=xkcd_transcriber&subject=delete&message=delete%20t1_d22h3p0)<|eor|><|eols|><|endoftext|> | 7 |
lolphp | hobabaObama | 740xwy | <|sols|><|sot|>I don't want my family and friends to be ashamed of me.<|eot|><|sol|>https://i.redd.it/31j8wsjhqmpz.png<|eol|><|eols|><|endoftext|> | 266 |
lolphp | TheBuzzSaw | dnur26w | <|sols|><|sot|>I don't want my family and friends to be ashamed of me.<|eot|><|sol|>https://i.redd.it/31j8wsjhqmpz.png<|eol|><|sor|>This made my day.<|eor|><|eols|><|endoftext|> | 17 |
lolphp | cosmicsans | dnw2scv | <|sols|><|sot|>I don't want my family and friends to be ashamed of me.<|eot|><|sol|>https://i.redd.it/31j8wsjhqmpz.png<|eol|><|sor|>PHP and C++ ? Those are 2 different jobs now, aren't they ?<|eor|><|sor|>No. a lot of Php applications that need some things to be super optimized will run those bits as C++ or just C. Go is also another go-to, but PHP is built on C, so C and C++ turn directly into PHP extensions so you can just use "PHP" calls to do things. <|eor|><|eols|><|endoftext|> | 14 |
lolphp | BillyIII | dnvgw75 | <|sols|><|sot|>I don't want my family and friends to be ashamed of me.<|eot|><|sol|>https://i.redd.it/31j8wsjhqmpz.png<|eol|><|sor|>This made my day.<|eor|><|sor|>Me too, I'm 12 btw.<|eor|><|sor|>I use arch.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | Apollidore | dnvzj8u | <|sols|><|sot|>I don't want my family and friends to be ashamed of me.<|eot|><|sol|>https://i.redd.it/31j8wsjhqmpz.png<|eol|><|sor|>PHP and C++ ? Those are 2 different jobs now, aren't they ?<|eor|><|eols|><|endoftext|> | 10 |
lolphp | mardukaz1 | do5s75q | <|sols|><|sot|>I don't want my family and friends to be ashamed of me.<|eot|><|sol|>https://i.redd.it/31j8wsjhqmpz.png<|eol|><|sor|>This made my day.<|eor|><|sor|>This made my day.... three months ago.
https://www.reddit.com/r/ProgrammerHumor/top/?sort=top&t=all
> literally first fucking post
> with better delivery<|eor|><|eols|><|endoftext|> | 9 |
lolphp | wecsam | dnv4q9u | <|sols|><|sot|>I don't want my family and friends to be ashamed of me.<|eot|><|sol|>https://i.redd.it/31j8wsjhqmpz.png<|eol|><|sor|>This made my day.<|eor|><|sor|>Me too, I'm 12 btw.<|eor|><|sor|>I'm 20.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | z500 | dnvdy51 | <|sols|><|sot|>I don't want my family and friends to be ashamed of me.<|eot|><|sol|>https://i.redd.it/31j8wsjhqmpz.png<|eol|><|sor|>This made my day.<|eor|><|sor|>Me too, I'm 12 btw.<|eor|><|sor|>I'm 20.<|eor|><|sor|>I'm 30 and I approve this message.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | urielsalis | f3d3al | <|sols|><|sot|>Function is no longer deprecated<|eot|><|sol|>https://i.imgur.com/RtsFKel.png<|eol|><|eols|><|endoftext|> | 260 |
lolphp | tobiasvl | fhim56z | <|sols|><|sot|>Function is no longer deprecated<|eot|><|sol|>https://i.imgur.com/RtsFKel.png<|eol|><|sor|>reprecated<|eor|><|eols|><|endoftext|> | 54 |
lolphp | urielsalis | fhi0yaq | <|sols|><|sot|>Function is no longer deprecated<|eot|><|sol|>https://i.imgur.com/RtsFKel.png<|eol|><|sor|>[deleted]<|eor|><|soopr|>https://www.php.net/manual/en/function.is-a.php<|eoopr|><|eols|><|endoftext|> | 27 |
lolphp | idontlikethisname | fhitba6 | <|sols|><|sot|>Function is no longer deprecated<|eot|><|sol|>https://i.imgur.com/RtsFKel.png<|eol|><|sor|>Stuff does get undeprecated. This is why deprecation cycles are a thing. And FFS, this was all the way back in 5.3<|eor|><|sor|>Well, PHP is much saner nowadays compared to the old days. How are we supposed to make fun of it?<|eor|><|eols|><|endoftext|> | 25 |
lolphp | chishiki | fhicdmg | <|sols|><|sot|>Function is no longer deprecated<|eot|><|sol|>https://i.imgur.com/RtsFKel.png<|eol|><|sor|>~~de~~precated<|eor|><|eols|><|endoftext|> | 22 |
lolphp | barubary | fhi0tzf | <|sols|><|sot|>Function is no longer deprecated<|eot|><|sol|>https://i.imgur.com/RtsFKel.png<|eol|><|sor|>[deleted]<|eor|><|sor|>[`is_a`](https://www.php.net/manual/en/function.is-a.php)<|eor|><|eols|><|endoftext|> | 20 |
lolphp | KokishinNeko | fhjjwkb | <|sols|><|sot|>Function is no longer deprecated<|eot|><|sol|>https://i.imgur.com/RtsFKel.png<|eol|><|sor|>So, deprecated warning is deprecated?<|eor|><|eols|><|endoftext|> | 16 |
lolphp | bkdotcom | fhifv7p | <|sols|><|sot|>Function is no longer deprecated<|eot|><|sol|>https://i.imgur.com/RtsFKel.png<|eol|><|sor|>I'll take "things that happened 11" years ago Alex.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | supermario182 | fhj1l3a | <|sols|><|sot|>Function is no longer deprecated<|eot|><|sol|>https://i.imgur.com/RtsFKel.png<|eol|><|sor|>De-deprecated<|eor|><|eols|><|endoftext|> | 7 |
lolphp | mongopeter | 4oacnc | <|sols|><|sot|>PHP and ISO 8601 (from php.net, link in comments)<|eot|><|sol|>http://i.imgur.com/ASxdrrF.png<|eol|><|eols|><|endoftext|> | 216 |
lolphp | coredumperror | d4b5b2z | <|sols|><|sot|>PHP and ISO 8601 (from php.net, link in comments)<|eot|><|sol|>http://i.imgur.com/ASxdrrF.png<|eol|><|sor|>I wish I could say that I'm surprised. I really, really wish that.<|eor|><|eols|><|endoftext|> | 35 |
lolphp | kasnalin | d4bas7r | <|sols|><|sot|>PHP and ISO 8601 (from php.net, link in comments)<|eot|><|sol|>http://i.imgur.com/ASxdrrF.png<|eol|><|sor|>I don't quite get it. In what way is it not compatible with an ISO date? It even has the annoying "T" between the date and the time part.<|eor|><|sor|>You have to either have the colon and hyphen separators in all components of the date and time, or none of them. In other words, it should be 2005-08-15T15:52:01+00:00, with a colon in the time zone designator.<|eor|><|eols|><|endoftext|> | 29 |
lolphp | yawkat | d4bdenr | <|sols|><|sot|>PHP and ISO 8601 (from php.net, link in comments)<|eot|><|sol|>http://i.imgur.com/ASxdrrF.png<|eol|><|sor|>That is so stupid... One of our APIs broke because they expected an ISO 8601 string and I really thought a constant named ISO8601 would give me an ISO 8601 string.
We had to hotfix the system and all testers had to start from the beginning. Fun times!<|eor|><|sor|>But it's documented, so it's fine! ^^\s<|eor|><|eols|><|endoftext|> | 27 |
lolphp | DevelopThePrograms | d4evcbj | <|sols|><|sot|>PHP and ISO 8601 (from php.net, link in comments)<|eot|><|sol|>http://i.imgur.com/ASxdrrF.png<|eol|><|sor|>That is so stupid... One of our APIs broke because they expected an ISO 8601 string and I really thought a constant named ISO8601 would give me an ISO 8601 string.
We had to hotfix the system and all testers had to start from the beginning. Fun times!<|eor|><|sor|>I don't understand why they don't fix shit like this for major versions, eg PHP7 which has some other backwards incompatible changes. Like just add it to the list of changes.
And I'd love to see the application that actual depends on the iso8601 constant being wrong. <|eor|><|eols|><|endoftext|> | 14 |
lolphp | carlos_vini | d4b1s00 | <|sols|><|sot|>PHP and ISO 8601 (from php.net, link in comments)<|eot|><|sol|>http://i.imgur.com/ASxdrrF.png<|eol|><|sor|>https://m.reddit.com/r/lolphp/comments/3nz2hd/datetimeformatdatetimeiso8601_doesnt_format_date/<|eor|><|eols|><|endoftext|> | 13 |
lolphp | mongopeter | d4aw1bz | <|sols|><|sot|>PHP and ISO 8601 (from php.net, link in comments)<|eot|><|sol|>http://i.imgur.com/ASxdrrF.png<|eol|><|soopr|>http://php.net/manual/en/class.datetime.php<|eoopr|><|eols|><|endoftext|> | 12 |
lolphp | bart2019 | d4bajrz | <|sols|><|sot|>PHP and ISO 8601 (from php.net, link in comments)<|eot|><|sol|>http://i.imgur.com/ASxdrrF.png<|eol|><|sor|>I don't quite get it. In what way is it not compatible with an ISO date? It even has the annoying "T" between the date and the time part.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | Synes_Godt_Om | d4bbhyf | <|sols|><|sot|>PHP and ISO 8601 (from php.net, link in comments)<|eot|><|sol|>http://i.imgur.com/ASxdrrF.png<|eol|><|sor|>This is a TRUE WTF. <|eor|><|eols|><|endoftext|> | 5 |
lolphp | midir | 4jhpv0 | <|sols|><|sot|>The default PHP session lifetime is 24 minutes, or 1440 seconds, because if it were 1440 minutes, then that would be exactly a day<|eot|><|sol|>http://stackoverflow.com/a/37176824<|eol|><|eols|><|endoftext|> | 193 |
lolphp | Deranged40 | d36qzla | <|sols|><|sot|>The default PHP session lifetime is 24 minutes, or 1440 seconds, because if it were 1440 minutes, then that would be exactly a day<|eot|><|sol|>http://stackoverflow.com/a/37176824<|eol|><|sor|>It was *supposed* to be 1 day. According to your post, it's 24 minutes because they switched the time from minute based to second based and nobody bothered to do the conversion<|eor|><|eols|><|endoftext|> | 59 |
lolphp | crankybadger | d379gfa | <|sols|><|sot|>The default PHP session lifetime is 24 minutes, or 1440 seconds, because if it were 1440 minutes, then that would be exactly a day<|eot|><|sol|>http://stackoverflow.com/a/37176824<|eol|><|sor|>I love all the people claiming crap like this:
>Because most website visitors have, at most, 24 minutes between requests when they stay on a website, any more and it can be assumed they've left the website.
>Because its a math nerd number thats approximately the same as what research shows is the largest time between two request in the same session (20-30 minutes).
Literally just people talking out of their asses.<|eor|><|sor|>In PHP the average of 20 and 30 is 24.
<|eor|><|eols|><|endoftext|> | 52 |
lolphp | emilvikstrom | d36qglm | <|sols|><|sot|>The default PHP session lifetime is 24 minutes, or 1440 seconds, because if it were 1440 minutes, then that would be exactly a day<|eot|><|sol|>http://stackoverflow.com/a/37176824<|eol|><|sor|>I have always wondered about this. I hate short session times! On our servers we always set it to two days.<|eor|><|eols|><|endoftext|> | 19 |
lolphp | BowserKoopa | d380cuc | <|sols|><|sot|>The default PHP session lifetime is 24 minutes, or 1440 seconds, because if it were 1440 minutes, then that would be exactly a day<|eot|><|sol|>http://stackoverflow.com/a/37176824<|eol|><|sor|>It was *supposed* to be 1 day. According to your post, it's 24 minutes because they switched the time from minute based to second based and nobody bothered to do the conversion<|eor|><|sor|>This is so typical of PHP.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | randomjackass | d37mkaw | <|sols|><|sot|>The default PHP session lifetime is 24 minutes, or 1440 seconds, because if it were 1440 minutes, then that would be exactly a day<|eot|><|sol|>http://stackoverflow.com/a/37176824<|eol|><|sor|>I love all the people claiming crap like this:
>Because most website visitors have, at most, 24 minutes between requests when they stay on a website, any more and it can be assumed they've left the website.
>Because its a math nerd number thats approximately the same as what research shows is the largest time between two request in the same session (20-30 minutes).
Literally just people talking out of their asses.<|eor|><|sor|>In PHP the average of 20 and 30 is 24.
<|eor|><|sor|>I'd figure after 20 minutes of PHP, most people would switch to something else. <|eor|><|eols|><|endoftext|> | 11 |
lolphp | emilvikstrom | d38g31b | <|sols|><|sot|>The default PHP session lifetime is 24 minutes, or 1440 seconds, because if it were 1440 minutes, then that would be exactly a day<|eot|><|sol|>http://stackoverflow.com/a/37176824<|eol|><|sor|>I have always wondered about this. I hate short session times! On our servers we always set it to two days.<|eor|><|sor|>I hope you have lots of memory or no visitors.<|eor|><|sor|>We are a pretty normal web host. Lots of small sites and a few web shops. Session files aren't that big. There are lots of other things to scale up before session storage.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | masklinn | 34sxw5 | <|sols|><|sot|>md5('240610708') == md5('QNKCDZO')<|eot|><|sol|>http://3v4l.org/tT4l8<|eol|><|eols|><|endoftext|> | 194 |
lolphp | masklinn | cqxs0yh | <|sols|><|sot|>md5('240610708') == md5('QNKCDZO')<|eot|><|sol|>http://3v4l.org/tT4l8<|eol|><|soopr|>The secret is that ` md5('240610708')` is `'0e462097431906509019562988736854'` and `md5('QNKCDZO')` is `'0e830400451993494058024219903391'`.
Both are of the form 0e{bunch of digits}, a valid scientific notation. So when PHP's `==` decides to convert *both* sides to numbers to see if it can get a match, they're both converted to `float(0)`, and thus the equality is true.<|eoopr|><|eols|><|endoftext|> | 155 |
lolphp | deviltreh1 | cqxuaep | <|sols|><|sot|>md5('240610708') == md5('QNKCDZO')<|eot|><|sol|>http://3v4l.org/tT4l8<|eol|><|soopr|>The secret is that ` md5('240610708')` is `'0e462097431906509019562988736854'` and `md5('QNKCDZO')` is `'0e830400451993494058024219903391'`.
Both are of the form 0e{bunch of digits}, a valid scientific notation. So when PHP's `==` decides to convert *both* sides to numbers to see if it can get a match, they're both converted to `float(0)`, and thus the equality is true.<|eoopr|><|sor|>Alright that's very interesting and I enjoyed learning about this flaw.
However: The probability of an md5 hash having the form \^0e\d+$ is somewhere around 1:10000000000. The probability of two md5 hashes having the form \^0e\d+$ is somewhere around 1:100000000000000000000. That's low enough for me to not care.
EDIT: Let's be exact. The probability of an md5 hash having the form \^0e\d+$ is of course
(1/16)^2 * (10/16)^30 2.93873588e-9 3:1000000000
So the probability of two md5 hashes having that form is
((1/16)^2 * (10/16)^30)^2 8.6361686e-18 9:1000000000000000000
<|eor|><|sor|>>That's low enough for me to not care.
Spoken like a true PHP developer considering security.<|eor|><|eols|><|endoftext|> | 153 |
lolphp | HiddenKrypt | cqxus4a | <|sols|><|sot|>md5('240610708') == md5('QNKCDZO')<|eot|><|sol|>http://3v4l.org/tT4l8<|eol|><|soopr|>The secret is that ` md5('240610708')` is `'0e462097431906509019562988736854'` and `md5('QNKCDZO')` is `'0e830400451993494058024219903391'`.
Both are of the form 0e{bunch of digits}, a valid scientific notation. So when PHP's `==` decides to convert *both* sides to numbers to see if it can get a match, they're both converted to `float(0)`, and thus the equality is true.<|eoopr|><|sor|>Alright that's very interesting and I enjoyed learning about this flaw.
However: The probability of an md5 hash having the form \^0e\d+$ is somewhere around 1:10000000000. The probability of two md5 hashes having the form \^0e\d+$ is somewhere around 1:100000000000000000000. That's low enough for me to not care.
EDIT: Let's be exact. The probability of an md5 hash having the form \^0e\d+$ is of course
(1/16)^2 * (10/16)^30 2.93873588e-9 3:1000000000
So the probability of two md5 hashes having that form is
((1/16)^2 * (10/16)^30)^2 8.6361686e-18 9:1000000000000000000
<|eor|><|sor|>>That's low enough for me to not care.
Spoken like a true PHP developer considering security.<|eor|><|sor|>If your security is based on MD5 and you're using two equals signs where you clearly should be using three, I don't think you have any business criticizing PHP developers. <|eor|><|eols|><|endoftext|> | 42 |
lolphp | madsohm | cqxu10w | <|sols|><|sot|>md5('240610708') == md5('QNKCDZO')<|eot|><|sol|>http://3v4l.org/tT4l8<|eol|><|soopr|>The secret is that ` md5('240610708')` is `'0e462097431906509019562988736854'` and `md5('QNKCDZO')` is `'0e830400451993494058024219903391'`.
Both are of the form 0e{bunch of digits}, a valid scientific notation. So when PHP's `==` decides to convert *both* sides to numbers to see if it can get a match, they're both converted to `float(0)`, and thus the equality is true.<|eoopr|><|sor|>I believe this would have shown the problem better: http://3v4l.org/5In2u <|eor|><|eols|><|endoftext|> | 36 |
lolphp | stevenhp1987 | cqxs4f8 | <|sols|><|sot|>md5('240610708') == md5('QNKCDZO')<|eot|><|sol|>http://3v4l.org/tT4l8<|eol|><|sor|>This is why you should use `===`for anything like this.<|eor|><|eols|><|endoftext|> | 33 |
lolphp | ZiggyTheHamster | cqy7ivv | <|sols|><|sot|>md5('240610708') == md5('QNKCDZO')<|eot|><|sol|>http://3v4l.org/tT4l8<|eol|><|soopr|>The secret is that ` md5('240610708')` is `'0e462097431906509019562988736854'` and `md5('QNKCDZO')` is `'0e830400451993494058024219903391'`.
Both are of the form 0e{bunch of digits}, a valid scientific notation. So when PHP's `==` decides to convert *both* sides to numbers to see if it can get a match, they're both converted to `float(0)`, and thus the equality is true.<|eoopr|><|sor|>Alright that's very interesting and I enjoyed learning about this flaw.
However: The probability of an md5 hash having the form \^0e\d+$ is somewhere around 1:10000000000. The probability of two md5 hashes having the form \^0e\d+$ is somewhere around 1:100000000000000000000. That's low enough for me to not care.
EDIT: Let's be exact. The probability of an md5 hash having the form \^0e\d+$ is of course
(1/16)^2 * (10/16)^30 2.93873588e-9 3:1000000000
So the probability of two md5 hashes having that form is
((1/16)^2 * (10/16)^30)^2 8.6361686e-18 9:1000000000000000000
<|eor|><|sor|>>That's low enough for me to not care.
Spoken like a true PHP developer considering security.<|eor|><|sor|>If your security is based on MD5 and you're using two equals signs where you clearly should be using three, I don't think you have any business criticizing PHP developers. <|eor|><|sor|>You should not be using `===` either.
You should be using [hash_equals](http://php.net/manual/en/function.hash-equals.php).<|eor|><|eols|><|endoftext|> | 29 |
lolphp | ZiggyTheHamster | cqy7jlk | <|sols|><|sot|>md5('240610708') == md5('QNKCDZO')<|eot|><|sol|>http://3v4l.org/tT4l8<|eol|><|sor|>This is why you should use `===`for anything like this.<|eor|><|sor|>No.
You should use [hash_equals](http://php.net/manual/en/function.hash-equals.php) and `===` everywhere else.<|eor|><|eols|><|endoftext|> | 27 |
lolphp | adambrenecki | csgp6st | <|sols|><|sot|>md5('240610708') == md5('QNKCDZO')<|eot|><|sol|>http://3v4l.org/tT4l8<|eol|><|sor|>The last one of these is the best, IMHO.
var_dump('0xABCdef' == ' 0xABCdef');
- `true` in 4.3.0 - 4.3.9
- `false` in 4.3.10 - 4.4.9
- `true` in 5.0.0 - 5.0.2
- `false` in 5.0.3 - 5.2.0
- `true` in 5.2.1+
- `false` in 7.0.0a1
Behaviour of basic operators totally changing between bugfix releases, you can't get more PHP than that!<|eor|><|eols|><|endoftext|> | 25 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.