subreddit stringclasses 7
values | author stringlengths 3 20 | id stringlengths 5 7 | content stringlengths 67 30.4k | score int64 0 140k |
|---|---|---|---|---|
lolphp | phoshi | cuxsygq | <|sols|><|sot|>Oh god. It's leaking in to the desktop realm.<|eot|><|sol|>https://github.com/mwgg/i3phtatus<|eol|><|sor|>I honestly think this is not much worse than using bash or Python. It's a simple and not too obscure language, you can do things quickly with it. And it works fine for that, I like to use PHP as a small upgrade when bash doesn't cut it (and I hate python and don't have ruby installed). Sure, I could make a C/C++/D/Rust/Go program and all, but it's overkill and not worth the effort for a simple 300 lines remote backup script that takes 5 minutes to write in PHP. If this guy has PHP already on his system and knows the language, why not? It's just spitting text for i3 to display anyway, it *is* the kind of scripts it was designed for.
What PHP was *not* made for is the huge millions of files web applications we see nowadays. Neither is it suitable to write a websocket server, or a GUI app. Or anything that's not just dumping a bunch of forms in a database really. Nobody sane would have designed a language *meant* to be used the way PHP is abused today. What makes PHP so horrible is the patchwork to retrofit features over features while breaking as less as possible. <|eor|><|sor|>PHP is a templating language, not a text processing one. Perl would be a decent choice here, but php has no real advantages over anything else. <|eor|><|eols|><|endoftext|> | 5 |
lolphp | Crashmatusow | cuzbmck | <|sols|><|sot|>Oh god. It's leaking in to the desktop realm.<|eot|><|sol|>https://github.com/mwgg/i3phtatus<|eol|><|sor|>I honestly think this is not much worse than using bash or Python. It's a simple and not too obscure language, you can do things quickly with it. And it works fine for that, I like to use PHP as a small upgrade when bash doesn't cut it (and I hate python and don't have ruby installed). Sure, I could make a C/C++/D/Rust/Go program and all, but it's overkill and not worth the effort for a simple 300 lines remote backup script that takes 5 minutes to write in PHP. If this guy has PHP already on his system and knows the language, why not? It's just spitting text for i3 to display anyway, it *is* the kind of scripts it was designed for.
What PHP was *not* made for is the huge millions of files web applications we see nowadays. Neither is it suitable to write a websocket server, or a GUI app. Or anything that's not just dumping a bunch of forms in a database really. Nobody sane would have designed a language *meant* to be used the way PHP is abused today. What makes PHP so horrible is the patchwork to retrofit features over features while breaking as less as possible. <|eor|><|sor|>Discrediting python or ruby does not help your argument however. Any sane language is good enough for small jobs.<|eor|><|sor|>Oh I'm in no way discrediting them. They're both miles ahead of PHP in my opinion. I just said I don't like Python (personal taste), that I didn't have Ruby installed (have nothing installed that uses it), and that PHP is good enough to read a few text files and format it (already have it because webdev, already know it too). I'm not even discrediting bash either: it does what it needs to do fine.<|eor|><|sor|>Python and/or Ruby are more likely to be installed on desktops than PHP.<|eor|><|sor|>Downvotes from people who have never really used a unix like system.
Not so sure about the ruby though<|eor|><|eols|><|endoftext|> | 5 |
lolphp | nic0nic | 37c64u | <|sols|><|sot|>Loving "Exception::getTraceAsString() simply sucks..."<|eot|><|sol|>http://php.net/manual/en/exception.gettraceasstring.php#114980<|eol|><|eols|><|endoftext|> | 33 |
lolphp | cjwelborn | crltopj | <|sols|><|sot|>Loving "Exception::getTraceAsString() simply sucks..."<|eot|><|sol|>http://php.net/manual/en/exception.gettraceasstring.php#114980<|eol|><|sor|>I like the comment from 'cotton' at the bottom:
>"this method uses \n for new line (i expected PHP_EOL but well ...)"
I don't know if there's any truth to that or not, but it would be weird to have `PHP_EOL` and then use a plain `\n` in the standard library.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | pacotes | 2kmjfm | <|sols|><|sot|>Go Home, WP-API, You're Drunk...<|eot|><|sol|>https://gist.github.com/sarciszewski/41dff863601ea7f45d51<|eol|><|eols|><|endoftext|> | 34 |
lolphp | bart2019 | clnnl0y | <|sols|><|sot|>Go Home, WP-API, You're Drunk...<|eot|><|sol|>https://gist.github.com/sarciszewski/41dff863601ea7f45d51<|eol|><|sor|>>WP-API, however, still has yet to even acknowledge the bug report sitting in the issue tracker for 17 days (and counting).
So people are not allowed to go on a vacation? They have to do free work all the time? What are they, slaves?
As if 17 days is that long.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | Vogtinator | 2gyaph | <|sols|><|sot|>Functions registered with register_shutdown_function are immune to execution time limit<|eot|><|sol|>http://php.net/manual/en/function.register-shutdown-function.php#113585<|eol|><|eols|><|endoftext|> | 32 |
lolphp | morphotomy | ckntkqu | <|sols|><|sot|>Functions registered with register_shutdown_function are immune to execution time limit<|eot|><|sol|>http://php.net/manual/en/function.register-shutdown-function.php#113585<|eol|><|sor|>sleep() and the like do not contribute to the time limit.
http://stackoverflow.com/questions/740954/does-sleep-time-count-for-execution-time-limit
IRRC database queries don't contribute to the timer either.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | DoctorWaluigiTime | cknpxwf | <|sols|><|sot|>Functions registered with register_shutdown_function are immune to execution time limit<|eot|><|sol|>http://php.net/manual/en/function.register-shutdown-function.php#113585<|eol|><|sor|>The real lol is the ordering of those user contributed notes.
Is it by score? Nope: 8, 7, 3, 7, 7...
By date! Nu-uh: 11 years ago, 10 months ago, 2 years ago, 4 years ago.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | olemartinorg | cknpv83 | <|sols|><|sot|>Functions registered with register_shutdown_function are immune to execution time limit<|eot|><|sol|>http://php.net/manual/en/function.register-shutdown-function.php#113585<|eol|><|sor|>Ahh, yeah. I found that out the *strange* way recently. A good thing though, in my case, because the error handler can even report when the max execution time has been reached. Hope there's no infinte loop in the error handler.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | nikic | cknvwlm | <|sols|><|sot|>Functions registered with register_shutdown_function are immune to execution time limit<|eot|><|sol|>http://php.net/manual/en/function.register-shutdown-function.php#113585<|eol|><|sor|>There is a timeout reset before shutdown function are run, but the timeout is still there. What this snippet actually shows is only that sleep does not count towards the timeout.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | doodle77 | 24vq5p | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|eols|><|endoftext|> | 31 |
lolphp | dochoncho | chb7kal | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>This isn't lol, 0 is considered empty/falsey, regardless if it's an integer or a string.<|eor|><|sor|>The fact that it does so is the Lol. Automatic type coersion of string to int to bool is a sick joke. I'd argue that strings should never be automatically cast. Sure, its slightly convenient occasionally, but the unintended side effects are disastrous.
Edit: spelling derp<|eor|><|eols|><|endoftext|> | 22 |
lolphp | h2ooooooo | chb6cyp | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>Did you read the [manual](http://www.php.net/empty)? Sure it might be confusing, but it's obviously by design.
> The following things are considered to be empty:
> `""` (an empty string)
> `0` (0 as an integer)
> `0.0` (0 as a float)
> `"0"` (0 as a string) <------
> `NULL`
> `FALSE`
> `array()` (an empty array)
> `$var;` (a variable declared, but without a value)<|eor|><|eols|><|endoftext|> | 17 |
lolphp | vytah | chbqx4g | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>Clearly PHP nees a `real_empty` function.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | andsens | chbas8o | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>Did you read the [manual](http://www.php.net/empty)? Sure it might be confusing, but it's obviously by design.
> The following things are considered to be empty:
> `""` (an empty string)
> `0` (0 as an integer)
> `0.0` (0 as a float)
> `"0"` (0 as a string) <------
> `NULL`
> `FALSE`
> `array()` (an empty array)
> `$var;` (a variable declared, but without a value)<|eor|><|soopr|>Of course I knew about it ([this is the more comprehensive page](http://us3.php.net/manual/en/types.comparisons.php)), I just consider it lolphp.<|eoopr|><|sor|>I agree with you completely. It's like the unix lesson of "do the thing that surprises users the least" totally went by the PHP maintainers.
I had to report [this bug](https://code.google.com/p/xmlseclibs/issues/detail?id=27) to xmlseclibs today, though it's really not the maintainers fault. Just PHP libraries being shitty once again.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | HaMMeReD | chbfsby | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>This isn't lol, 0 is considered empty/falsey, regardless if it's an integer or a string.<|eor|><|sor|>The fact that it does so is the Lol. Automatic type coersion of string to int to bool is a sick joke. I'd argue that strings should never be automatically cast. Sure, its slightly convenient occasionally, but the unintended side effects are disastrous.
Edit: spelling derp<|eor|><|sor|>Yeah, but it's not "lol" in the context of PHP, its documented functionality.<|eor|><|sor|>The fact that it's documented and not a bug ticket/fix scheduled for the next major version is lol in itself.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | doodle77 | chb6jy7 | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>Did you read the [manual](http://www.php.net/empty)? Sure it might be confusing, but it's obviously by design.
> The following things are considered to be empty:
> `""` (an empty string)
> `0` (0 as an integer)
> `0.0` (0 as a float)
> `"0"` (0 as a string) <------
> `NULL`
> `FALSE`
> `array()` (an empty array)
> `$var;` (a variable declared, but without a value)<|eor|><|soopr|>Of course I knew about it ([this is the more comprehensive page](http://us3.php.net/manual/en/types.comparisons.php)), I just consider it lolphp.<|eoopr|><|eols|><|endoftext|> | 11 |
lolphp | h0rst_ | chb4ama | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>[deleted]<|eor|><|sor|>http://codepad.viper-7.com/gugBKS
I don't really think that's the problem.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | DoctorWaluigiTime | chbcvmd | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>This isn't lol, 0 is considered empty/falsey, regardless if it's an integer or a string.<|eor|><|sor|>The fact that it does so is the Lol. Automatic type coersion of string to int to bool is a sick joke. I'd argue that strings should never be automatically cast. Sure, its slightly convenient occasionally, but the unintended side effects are disastrous.
Edit: spelling derp<|eor|><|sor|>Yeah, but it's not "lol" in the context of PHP, its documented functionality.<|eor|><|sor|>I think at least half of the lolphp submissions are remarks on how ludicrous the documentation tries to excuse PHP's behavior away.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | HelloAnnyong | chbl3fy | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>This isn't lol, 0 is considered empty/falsey, regardless if it's an integer or a string.<|eor|><|sor|>Putting a slash between empty and falsy doesn't make them equivalent concepts. I buy that 0 or even "0" is falsy. But the word "empty" means things in English and mathematics. And it is very unintuitive for the string "0" to be empty.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | ajmarks | chb9ckk | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>This isn't lol, 0 is considered empty/falsey, regardless if it's an integer or a string.<|eor|><|sor|>The fact that it does so is the Lol. Automatic type coersion of string to int to bool is a sick joke. I'd argue that strings should never be automatically cast. Sure, its slightly convenient occasionally, but the unintended side effects are disastrous.
Edit: spelling derp<|eor|><|sor|>Coercion. The word you want is coercion.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | HaMMeReD | chbfq3q | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>Did you read the [manual](http://www.php.net/empty)? Sure it might be confusing, but it's obviously by design.
> The following things are considered to be empty:
> `""` (an empty string)
> `0` (0 as an integer)
> `0.0` (0 as a float)
> `"0"` (0 as a string) <------
> `NULL`
> `FALSE`
> `array()` (an empty array)
> `$var;` (a variable declared, but without a value)<|eor|><|sor|>Just because something is documented doesn't mean it's by design.
I think because of PHP's softly typed nature, "0" = 0 = "" in the system, and this is a bug due to that, but thanks to PHP supporting it's own bugs, they've added it to the documentation so that you know the behaviour.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | Sarcastinator | chbpxro | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>[deleted]<|eor|><|sor|>http://codepad.viper-7.com/gugBKS
I don't really think that's the problem.<|eor|><|sor|>[deleted]<|eor|><|sor|>It's still ridiculous and unintuitive behavior.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | captainramen | chbez98 | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>Did you read the [manual](http://www.php.net/empty)? Sure it might be confusing, but it's obviously by design.
> The following things are considered to be empty:
> `""` (an empty string)
> `0` (0 as an integer)
> `0.0` (0 as a float)
> `"0"` (0 as a string) <------
> `NULL`
> `FALSE`
> `array()` (an empty array)
> `$var;` (a variable declared, but without a value)<|eor|><|sor|>And yet "00" is not considered empty. I can imagine some validation code to disallow empty values on fields blowing up because of this. The WTF continues.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | HaMMeReD | chbgxlj | <|sols|><|sot|>That's an empty string, right?<|eot|><|sol|>http://codepad.viper-7.com/lg3Sk4<|eol|><|sor|>This isn't lol, 0 is considered empty/falsey, regardless if it's an integer or a string.<|eor|><|sor|>The fact that it does so is the Lol. Automatic type coersion of string to int to bool is a sick joke. I'd argue that strings should never be automatically cast. Sure, its slightly convenient occasionally, but the unintended side effects are disastrous.
Edit: spelling derp<|eor|><|sor|>Yeah, but it's not "lol" in the context of PHP, its documented functionality.<|eor|><|sor|>The fact that it's documented and not a bug ticket/fix scheduled for the next major version is lol in itself.<|eor|><|sor|>Well, because technically, it's not a bug.<|eor|><|sor|>That's just like your opinion, man.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | Arsene_Lupin | 1aordw | <|sols|><|sot|>file_put_contents return false but still write a file with size 0 when the directory is full<|eot|><|sol|>http://stackoverflow.com/questions/14165404/when-file-put-contents-fails-if-the-directory-is-full-a-file-with-size-0-is-cre<|eol|><|eols|><|endoftext|> | 34 |
lolphp | MrDOS | c8ze9qg | <|sols|><|sot|>file_put_contents return false but still write a file with size 0 when the directory is full<|eot|><|sol|>http://stackoverflow.com/questions/14165404/when-file-put-contents-fails-if-the-directory-is-full-a-file-with-size-0-is-cre<|eol|><|sor|>"You should not compare $success to FALSE because This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. - php.net/manual/en/function.file-put-contents.php vojtek Jan 4 at 21:47"
Uhhh... Okay...<|eor|><|sor|> var_dump(0 == false); // true
var_dump(0 === false); // false
Unless you were remarking on the stupidity of not having all error conditions return `false`, in which case your remark is right on the money.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | jdiez17 | c8zdrfn | <|sols|><|sot|>file_put_contents return false but still write a file with size 0 when the directory is full<|eot|><|sol|>http://stackoverflow.com/questions/14165404/when-file-put-contents-fails-if-the-directory-is-full-a-file-with-size-0-is-cre<|eol|><|sor|>"You should not compare $success to FALSE because This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. - php.net/manual/en/function.file-put-contents.php vojtek Jan 4 at 21:47"
Uhhh... Okay...<|eor|><|eols|><|endoftext|> | 6 |
lolphp | kaaskop42 | 16of2r | <|sols|><|sot|>PHP 5.4 hasn't register_globals anymore - That's my workaround for this.<|eot|><|sol|>http://www.reddit.com/r/linuxadmin/comments/16npyi/php_54_hasnt_register_globals_anymore_thats_my/<|eol|><|eols|><|endoftext|> | 35 |
lolphp | nikomo | c7xyynd | <|sols|><|sot|>PHP 5.4 hasn't register_globals anymore - That's my workaround for this.<|eot|><|sol|>http://www.reddit.com/r/linuxadmin/comments/16npyi/php_54_hasnt_register_globals_anymore_thats_my/<|eol|><|sor|>This is Facepalm Level 5 failure right here.
I certainly understand "oh crap, production's busted, fix this *real quick*" crisis mode, but this is probably the worst possible choice that could have been made apart from just running *rm -Rf /* as root^1 on the server.
^1 Note to new Unix/Linux admins: do not actually do this; it deletes all files on all mounted filesystems. If you simply must try it, use a development machine or a throwaway virtual machine. I know, I know, the disclaimer ruins the joke a bit, but I don't want any busted servers on my conscience ;)<|eor|><|sor|>>Note to new Unix/Linux admins: do not actually do this; it deletes all files on all mounted filesystems.
FYI, it doesn't do that on pretty much any modern Linux system, you have to confirm that you're a massive idiot with --no-preserve-root<|eor|><|eols|><|endoftext|> | 13 |
lolphp | svens_ | c7yhies | <|sols|><|sot|>PHP 5.4 hasn't register_globals anymore - That's my workaround for this.<|eot|><|sol|>http://www.reddit.com/r/linuxadmin/comments/16npyi/php_54_hasnt_register_globals_anymore_thats_my/<|eol|><|sor|>This is Facepalm Level 5 failure right here.
I certainly understand "oh crap, production's busted, fix this *real quick*" crisis mode, but this is probably the worst possible choice that could have been made apart from just running *rm -Rf /* as root^1 on the server.
^1 Note to new Unix/Linux admins: do not actually do this; it deletes all files on all mounted filesystems. If you simply must try it, use a development machine or a throwaway virtual machine. I know, I know, the disclaimer ruins the joke a bit, but I don't want any busted servers on my conscience ;)<|eor|><|sor|>[deleted]<|eor|><|sor|>> but the average PHP coder just doesn't care
...or is confused by the myriad escaping functions in PHP that seem like they might help but don't.<|eor|><|sor|>mysql_i_am_serious_this_time_real_escape<|eor|><|sor|>> mysql_i_am_serious_this_time_real_escape**_string**<|eor|><|eols|><|endoftext|> | 13 |
lolphp | willfe42 | c7xuph5 | <|sols|><|sot|>PHP 5.4 hasn't register_globals anymore - That's my workaround for this.<|eot|><|sol|>http://www.reddit.com/r/linuxadmin/comments/16npyi/php_54_hasnt_register_globals_anymore_thats_my/<|eol|><|sor|>This is Facepalm Level 5 failure right here.
I certainly understand "oh crap, production's busted, fix this *real quick*" crisis mode, but this is probably the worst possible choice that could have been made apart from just running *rm -Rf /* as root^1 on the server.
^1 Note to new Unix/Linux admins: do not actually do this; it deletes all files on all mounted filesystems. If you simply must try it, use a development machine or a throwaway virtual machine. I know, I know, the disclaimer ruins the joke a bit, but I don't want any busted servers on my conscience ;)<|eor|><|eols|><|endoftext|> | 11 |
lolphp | MrDOS | c8jdfte | <|sols|><|sot|>PHP 5.4 hasn't register_globals anymore - That's my workaround for this.<|eot|><|sol|>http://www.reddit.com/r/linuxadmin/comments/16npyi/php_54_hasnt_register_globals_anymore_thats_my/<|eol|><|sor|>I don't see how the [`extract`](http://prototype.php.net/extract) function escaped the author of the [other solution](http://php.net/manual/en/security.globals.php#82213) if you're going to do something godawful, you might as well do it right:
foreach(str_split(ini_get('variables-order')) as $superglobal)
{
switch($superglobal)
{
case 'E': extract($_ENV); break;
case 'G': extract($_GET); break;
case 'P': extract($_POST); break;
case 'C': extract($_COOKIE); break;
case 'S': extract($_SERVER); break;
}
}
Run it in the global scope (perhaps as an autoprepend as suggested in the other reddit post), and you're done. While I've not actually tried it (and I hope nobody else does, either), the fact that `extract` is a library-implemented function leads me to think that this is probably way faster.
Not that speed really matters when you're essentially hammering yourself in the balls with a crowbar, I guess.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | esquilax | c7y3bjj | <|sols|><|sot|>PHP 5.4 hasn't register_globals anymore - That's my workaround for this.<|eot|><|sol|>http://www.reddit.com/r/linuxadmin/comments/16npyi/php_54_hasnt_register_globals_anymore_thats_my/<|eol|><|sor|>This is Facepalm Level 5 failure right here.
I certainly understand "oh crap, production's busted, fix this *real quick*" crisis mode, but this is probably the worst possible choice that could have been made apart from just running *rm -Rf /* as root^1 on the server.
^1 Note to new Unix/Linux admins: do not actually do this; it deletes all files on all mounted filesystems. If you simply must try it, use a development machine or a throwaway virtual machine. I know, I know, the disclaimer ruins the joke a bit, but I don't want any busted servers on my conscience ;)<|eor|><|sor|>[deleted]<|eor|><|sor|>> but the average PHP coder just doesn't care
...or is confused by the myriad escaping functions in PHP that seem like they might help but don't.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | ealf | kmbpo | <|sols|><|sot|>Method names are case insensitive, unless you're calling a forwarded method on a FilterIterator, in which case you must include at least one uppercase letter in the method name for it to work. Even if the name of the actual method you're calling does not have one.<|eot|><|sol|>http://codepad.org/c7ewg1yc<|eol|><|eols|><|endoftext|> | 35 |
lolphp | ealf | c2mw6zi | <|sols|><|sot|>Method names are case insensitive, unless you're calling a forwarded method on a FilterIterator, in which case you must include at least one uppercase letter in the method name for it to work. Even if the name of the actual method you're calling does not have one.<|eot|><|sol|>http://codepad.org/c7ewg1yc<|eol|><|sor|>Looks like a straight-forward bug -- if I were you, I'd submit a ticket about it. It's not an LOLPHP unless they decide, for some reason, it's not actually a bug.<|eor|><|soopr|>You had me convinced for a little while, so I went and checked their bug tracker. [It was reported over a year ago](https://bugs.php.net/bug.php?id=52559).
The lolphp is that FilterIterator and 30 other iterator classes (someone over there [really likes iterators](http://us3.php.net/manual/en/class.recursiveiteratoriterator.php)) are *all written from scratch in C* rather than being written in the language itself. I guess they didn't want to sacrifice any of that blazing speed.<|eoopr|><|eols|><|endoftext|> | 13 |
lolphp | Rhomboid | c2lixhc | <|sols|><|sot|>Method names are case insensitive, unless you're calling a forwarded method on a FilterIterator, in which case you must include at least one uppercase letter in the method name for it to work. Even if the name of the actual method you're calling does not have one.<|eot|><|sol|>http://codepad.org/c7ewg1yc<|eol|><|sor|>I suppose that's what happens when you bolt on inheritance to a language that is already schizophrenic about case: function names, keywords, builtins are insensitive, while variables, constants, array keys, and properties are sensitive.
IF(!STRCMP($THIS, "EVIL")) {
ECHO "PHP EVIL";
}
<|eor|><|eols|><|endoftext|> | 9 |
lolphp | ealf | c2of49d | <|sols|><|sot|>Method names are case insensitive, unless you're calling a forwarded method on a FilterIterator, in which case you must include at least one uppercase letter in the method name for it to work. Even if the name of the actual method you're calling does not have one.<|eot|><|sol|>http://codepad.org/c7ewg1yc<|eol|><|sor|>Looks like a straight-forward bug -- if I were you, I'd submit a ticket about it. It's not an LOLPHP unless they decide, for some reason, it's not actually a bug.<|eor|><|soopr|>You had me convinced for a little while, so I went and checked their bug tracker. [It was reported over a year ago](https://bugs.php.net/bug.php?id=52559).
The lolphp is that FilterIterator and 30 other iterator classes (someone over there [really likes iterators](http://us3.php.net/manual/en/class.recursiveiteratoriterator.php)) are *all written from scratch in C* rather than being written in the language itself. I guess they didn't want to sacrifice any of that blazing speed.<|eoopr|><|sor|>> The lolphp is that FilterIterator and 30 other iterator classes (someone over there really likes iterators) are all written from scratch in C rather than being written in the language itself.
Being written in C is the *entire point* of SPL. If you want a pure PHP solution, you can easily write that yourself.
However, the SPL is some kind of bastard project that grows without bounds (who the fuck needs all these iterators) and is seemingly in perpetual beta. I avoid it.
<|eor|><|soopr|>> Being written in C is the *entire point* of SPL. If you want a pure PHP solution, you can easily write that yourself.
If I did, it would just be "a" PHP library. I would have thought the defining feature of a "Standard" PHP Library would be that it was available by default, not how it was implemented...
Then again, if writing the first function from scratch in C is easier than adding a module system, and writing the second function from scratch in C is easier than writing a module system, by php induction, this is all reasonable.<|eoopr|><|sor|>In nearly all interpreted languages, the "standard" library is written C. This goes for Perl, Python, Ruby, etc. The defining feature is not that PHP *comes with* the library, it's that the library is built into PHP.
PHP developers are C programmers first and PHP programmers a distant second. So, of course, the mindset is to build it in C.
I actually think the SPL is pretty terrible and I think something like that should be implemented purely in PHP (where possible) but really I don't like the idea of one library being bundled with PHP. Rather than an ecosystem of many frameworks with different pros and cons we'd end up with one framework that would look something like Zend (*yuck*).
<|eor|><|soopr|>> In nearly all interpreted languages, the "standard" library is written C. This goes for Perl, Python, Ruby, etc
This is quite simply not true, and I'm unable to come up with any interpretation of the words involved that would make it true, other than defining "standard library" as "the part of the library that is written in C".<|eoopr|><|eols|><|endoftext|> | 7 |
lolphp | wvenable | c2mhdyg | <|sols|><|sot|>Method names are case insensitive, unless you're calling a forwarded method on a FilterIterator, in which case you must include at least one uppercase letter in the method name for it to work. Even if the name of the actual method you're calling does not have one.<|eot|><|sol|>http://codepad.org/c7ewg1yc<|eol|><|sor|>Looks like a straight-forward bug -- if I were you, I'd submit a ticket about it. It's not an LOLPHP unless they decide, for some reason, it's not actually a bug.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | phplovesong | gvo1ky | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|eoss|><|endoftext|> | 31 |
lolphp | elcapitanoooo | fspxmax | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>PHP DateTime is a can of worms. Theres numerous issues with how it works. The funny thing is they made a "Immutable Datetime" clone of the class, and it turned out it never was really immutable. Many devs around the world probably have lost their minds with this.
TLDR. When working with date heavy apps, dont use PHP.<|eor|><|eoss|><|endoftext|> | 27 |
lolphp | jtbrinkmann | fspybb4 | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>I mean, it does the most logical thing, even though it's kind of weird.<|eor|><|sor|>IMO the most logical thing is **fail fast**<|eor|><|eoss|><|endoftext|> | 15 |
lolphp | rivendell_elf | fsq3g93 | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>PHP DateTime is a can of worms. Theres numerous issues with how it works. The funny thing is they made a "Immutable Datetime" clone of the class, and it turned out it never was really immutable. Many devs around the world probably have lost their minds with this.
TLDR. When working with date heavy apps, dont use PHP.<|eor|><|sor|>Or use PHP but with a more stable library like Carbon.<|eor|><|eoss|><|endoftext|> | 13 |
lolphp | spilk | fsr0xxd | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>in some locales a 24:31:41 time would be valid. I've seen it used in japan a lot to indicate closing times of late-night venues<|eor|><|eoss|><|endoftext|> | 12 |
lolphp | Luvax | fss5l0w | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>Well you guys think this is a problem. I tell you, this function can actually parse a lot of natural language strings into resonable dates. You might be tempted to start looking for sharp objects around you to stab me, so let me explain:
I've written a chat bot for a small chat channel and am actually calling the php binary to handle user input for a timer command. Because it's unbelievably hard to find good libraries for the job (regardless of programming language) and even in cases where it breaks, you still have something to laught at.
Try it, you can throw a lot of shit in constructor and will get a proper date. That said: This functionality should not exist in a class that appears to be used for accurate date parsing. But what do I care, I don't actually use this crap, I just use the date parser \\\_()\_/<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | Takeoded | fsqppkq | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>what are you guys talking about? https://3v4l.org/HPVDB - since at least PHP 5.2.0,
```
<?php
$loldate = new DateTime('2020-01-01 25:31:41');
var_dump($loldate);
```
results in
```
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (2020-01-01 25:31:41) at position 11 (2): Unexpected character in /in/HPVDB:3
Stack trace:
#0 /in/HPVDB(3): DateTime->__construct('2020-01-01 25:3...')
#1 {main}
thrown in /in/HPVDB on line 3
Process exited with code 255.
```
which is the correct course of action, isn't it?<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | elcapitanoooo | fsq0ysm | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>I mean, it does the most logical thing, even though it's kind of weird.<|eor|><|sor|>> I mean, it does the most logical thing
This sums up PHP in a nutshell. PHP does things "thats maybe correct", might work in 70% of cases, but the rest 30% the result is a silent bug thats possibly not immediately noticed.
This mentality is spread across the language, and can be found almost in every core function.<|eor|><|eoss|><|endoftext|> | 9 |
lolphp | duskwuff | fsrvvu6 | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>PHP DateTime is a can of worms. Theres numerous issues with how it works. The funny thing is they made a "Immutable Datetime" clone of the class, and it turned out it never was really immutable. Many devs around the world probably have lost their minds with this.
TLDR. When working with date heavy apps, dont use PHP.<|eor|><|sor|>Or use PHP but with a more stable library like Carbon.<|eor|><|sor|>Carbon doesn't solve all the problems with DateTime; it merely works around some of them. (It extends DateTime, after all -- it's not a completely new implementation.)<|eor|><|eoss|><|endoftext|> | 9 |
lolphp | dubl0dude | fsro0x3 | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>These comments are filled with people who were deeply hurt by PHP. They may never fully recover from their trauma.<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | scatters | fsqzz4m | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>Parsing arbitrary date strings without a specified format is a crapshoot and can only be done on a best-effort basis. I don't think it's better in other languages because it's fundamentally a bad idea.<|eor|><|sor|>Dont know all the ins-and-outs of the PHP date string parser, but its real simple to accept a correct time 00:00:00 - 23:59:59, hell this can even be done with a regex. I mean PHP accepting something like 24:20:20 is just plain wrong and should be considered a bug.
In python this:
datetime.fromisoformat('2011-11-04 24:00:00')
Throws an error, just as it should<|eor|><|sor|>So uh,
a) 23:59:60 is a valid time on days that have a leap second,
b) Public transport and TV schedules commonly use hours past 23 for times past midnight that count as part of the previous day<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | Takeoded | fsr0cbl | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>Parsing arbitrary date strings without a specified format is a crapshoot and can only be done on a best-effort basis. I don't think it's better in other languages because it's fundamentally a bad idea.<|eor|><|sor|>Dont know all the ins-and-outs of the PHP date string parser, but its real simple to accept a correct time 00:00:00 - 23:59:59, hell this can even be done with a regex. I mean PHP accepting something like 24:20:20 is just plain wrong and should be considered a bug.
In python this:
datetime.fromisoformat('2011-11-04 24:00:00')
Throws an error, just as it should<|eor|><|sor|>> its real simple to accept a correct time
The strings you need to accept in the real world are not necessarily correct, unfortunately.
> In python this: datetime.fromisoformat('2011-11-04 24:00:00')
>Throws an error, just as it should
That's not the same thing, you specified the format!<|eor|><|sor|>No matter, PHP still gets it wrong even if i did specify the format:
DateTime::createFromFormat(DateTime::ISO8601, '2020-01-01T24:31:41Z')
Returns an incorrect date, even though it should throw.
Edit.
Holy hell, i tried different values, and PHP accepts all ints up to 99, so this:
DateTime::createFromFormat(DateTime::ISO8601, '2020-01-01T99:99:99Z');
Is considered a "valid PHP datetime".<|eor|><|sor|> $ php -r "var_dump(DateTime::createFromFormat(DateTime::ISO8601, '2020-01-01T24:31:41Z'), DateTime::getLastErrors());"
object(DateTime)#1 (3) {
["date"]=>
string(26) "2020-01-02 00:31:41.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(1) "Z"
}
array(4) {
["warning_count"]=>
int(1)
["warnings"]=>
array(1) {
[20]=>
string(27) "The parsed time was invalid"
}
["error_count"]=>
int(0)
["errors"]=>
array(0) {
}
}
There ought to be a flag to make this throw, I agree.<|eor|><|sor|>> DateTime::getLastErrors()
why is this static using some global list of errors? shouldn't this be non-static and tied to the relevant DateTime object?<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | elcapitanoooo | fsrljzu | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>PHP DateTime is a can of worms. Theres numerous issues with how it works. The funny thing is they made a "Immutable Datetime" clone of the class, and it turned out it never was really immutable. Many devs around the world probably have lost their minds with this.
TLDR. When working with date heavy apps, dont use PHP.<|eor|><|sor|>Can you point to some more info or an example of mutable `DateTimeImmutable`s? It's not an easily searched topic.<|eor|><|sor|>Well, dont have any specific links. But there is bugs that make the immutable mutate its inner state, like when you print it etc.
Edit, heres one:
https://www.reddit.com/r/lolphp/comments/3fhpd0/how_to_modify_datetimeimmutable_call_gettimestamp/?utm_source=amp&utm_medium=&utm_content=post_title<|eor|><|eoss|><|endoftext|> | 7 |
lolphp | phplovesong | fsq5rpw | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>I mean, it does the most logical thing, even though it's kind of weird.<|eor|><|sor|>IMO the most logical thing is **fail fast**<|eor|><|sor|>The problem is there's a surprising number of incorrect date strings out there that you have to accept for such a function to be useful.<|eor|><|soopr|>Could you provide an example "of a incorrect string that PHP MUST accept"? Your whole sentence made no sense to me, why accept it if its incorrect in the first place? Why not throw an error and save the developer from painful debugging moments in the future?<|eoopr|><|eoss|><|endoftext|> | 7 |
lolphp | the_alias_of_andrea | fsq6v9c | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>Parsing arbitrary date strings without a specified format is a crapshoot and can only be done on a best-effort basis. I don't think it's better in other languages because it's fundamentally a bad idea.<|eor|><|sor|>Dont know all the ins-and-outs of the PHP date string parser, but its real simple to accept a correct time 00:00:00 - 23:59:59, hell this can even be done with a regex. I mean PHP accepting something like 24:20:20 is just plain wrong and should be considered a bug.
In python this:
datetime.fromisoformat('2011-11-04 24:00:00')
Throws an error, just as it should<|eor|><|sor|>> its real simple to accept a correct time
The strings you need to accept in the real world are not necessarily correct, unfortunately.
> In python this: datetime.fromisoformat('2011-11-04 24:00:00')
>Throws an error, just as it should
That's not the same thing, you specified the format!<|eor|><|sor|>No matter, PHP still gets it wrong even if i did specify the format:
DateTime::createFromFormat(DateTime::ISO8601, '2020-01-01T24:31:41Z')
Returns an incorrect date, even though it should throw.
Edit.
Holy hell, i tried different values, and PHP accepts all ints up to 99, so this:
DateTime::createFromFormat(DateTime::ISO8601, '2020-01-01T99:99:99Z');
Is considered a "valid PHP datetime".<|eor|><|sor|> $ php -r "var_dump(DateTime::createFromFormat(DateTime::ISO8601, '2020-01-01T24:31:41Z'), DateTime::getLastErrors());"
object(DateTime)#1 (3) {
["date"]=>
string(26) "2020-01-02 00:31:41.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(1) "Z"
}
array(4) {
["warning_count"]=>
int(1)
["warnings"]=>
array(1) {
[20]=>
string(27) "The parsed time was invalid"
}
["error_count"]=>
int(0)
["errors"]=>
array(0) {
}
}
There ought to be a flag to make this throw, I agree.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | elcapitanoooo | fsqxutv | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>what are you guys talking about? https://3v4l.org/HPVDB - since at least PHP 5.2.0,
```
<?php
$loldate = new DateTime('2020-01-01 25:31:41');
var_dump($loldate);
```
results in
```
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (2020-01-01 25:31:41) at position 11 (2): Unexpected character in /in/HPVDB:3
Stack trace:
#0 /in/HPVDB(3): DateTime->__construct('2020-01-01 25:3...')
#1 {main}
thrown in /in/HPVDB on line 3
Process exited with code 255.
```
which is the correct course of action, isn't it?<|eor|><|sor|>Looks like someone modified the gist. Change to 24:31:41 and see it "work"<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | elcapitanoooo | fsr44xy | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>Parsing arbitrary date strings without a specified format is a crapshoot and can only be done on a best-effort basis. I don't think it's better in other languages because it's fundamentally a bad idea.<|eor|><|sor|>Dont know all the ins-and-outs of the PHP date string parser, but its real simple to accept a correct time 00:00:00 - 23:59:59, hell this can even be done with a regex. I mean PHP accepting something like 24:20:20 is just plain wrong and should be considered a bug.
In python this:
datetime.fromisoformat('2011-11-04 24:00:00')
Throws an error, just as it should<|eor|><|sor|>So uh,
a) 23:59:60 is a valid time on days that have a leap second,
b) Public transport and TV schedules commonly use hours past 23 for times past midnight that count as part of the previous day<|eor|><|sor|>Dates are messy for sure. But the way you show them to a user should not be the same way you construct them in the codebase. Also a leap second is not something you usually need to worry about in parsing a iso formatted string<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | jtbrinkmann | fsqd6cf | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>I mean, it does the most logical thing, even though it's kind of weird.<|eor|><|sor|>IMO the most logical thing is **fail fast**<|eor|><|sor|>The problem is there's a surprising number of incorrect date strings out there that you have to accept for such a function to be useful.<|eor|><|soopr|>Could you provide an example "of a incorrect string that PHP MUST accept"? Your whole sentence made no sense to me, why accept it if its incorrect in the first place? Why not throw an error and save the developer from painful debugging moments in the future?<|eoopr|><|sor|>The classic example is that, for some reason, the usual date format used in HTTP and email headers contains both the day of the week (e.g. Wed) _and_ the day of the month (e.g. 13), and then implementations output a date in the far future with an incorrect day of the week. You have to accept these broken dates, because everyone else does.
But again, parsing a datetime string without a specified format is a crapshoot.<|eor|><|sor|>Which is why a good API either requires specifying a format, or forces a format on you (e.g. ISO 8601, i.e. the real ISO8601, not the [PHP similar-to-but-not-actually ISO 8601](https://www.reddit.com/r/lolphp/comments/3nz2hd/datetimeformatdatetimeiso8601_doesnt_format_date/))<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | intuxikated | fsrx0e9 | <|soss|><|sot|>PHP datetime accepts almost anything<|eot|><|sost|>When working with php datetime class, you constantly run into weird cases, heres another one that caused bugs.
[https://repl.it/repls/PertinentAggressiveBoolean](https://repl.it/repls/PertinentAggressiveBoolean)
Basically you can init the class with an incorrect date and PHP silently does its thing and converts it. In a real language this would throw an error, and only accept times between 00:00:00-23:59:59<|eost|><|sor|>Parsing arbitrary date strings without a specified format is a crapshoot and can only be done on a best-effort basis. I don't think it's better in other languages because it's fundamentally a bad idea.<|eor|><|sor|>Dont know all the ins-and-outs of the PHP date string parser, but its real simple to accept a correct time 00:00:00 - 23:59:59, hell this can even be done with a regex. I mean PHP accepting something like 24:20:20 is just plain wrong and should be considered a bug.
In python this:
datetime.fromisoformat('2011-11-04 24:00:00')
Throws an error, just as it should<|eor|><|sor|>> its real simple to accept a correct time
The strings you need to accept in the real world are not necessarily correct, unfortunately.
> In python this: datetime.fromisoformat('2011-11-04 24:00:00')
>Throws an error, just as it should
That's not the same thing, you specified the format!<|eor|><|sor|>No matter, PHP still gets it wrong even if i did specify the format:
DateTime::createFromFormat(DateTime::ISO8601, '2020-01-01T24:31:41Z')
Returns an incorrect date, even though it should throw.
Edit.
Holy hell, i tried different values, and PHP accepts all ints up to 99, so this:
DateTime::createFromFormat(DateTime::ISO8601, '2020-01-01T99:99:99Z');
Is considered a "valid PHP datetime".<|eor|><|sor|> $ php -r "var_dump(DateTime::createFromFormat(DateTime::ISO8601, '2020-01-01T24:31:41Z'), DateTime::getLastErrors());"
object(DateTime)#1 (3) {
["date"]=>
string(26) "2020-01-02 00:31:41.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(1) "Z"
}
array(4) {
["warning_count"]=>
int(1)
["warnings"]=>
array(1) {
[20]=>
string(27) "The parsed time was invalid"
}
["error_count"]=>
int(0)
["errors"]=>
array(0) {
}
}
There ought to be a flag to make this throw, I agree.<|eor|><|sor|>> DateTime::getLastErrors()
why is this static using some global list of errors? shouldn't this be non-static and tied to the relevant DateTime object?<|eor|><|sor|>That would make too much sense.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | SaraMG | 8ls8a0 | <|sols|><|sot|>PHP needs mutable constants, and immutable variables, and functions with properties!<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8lrrac/why_does_php_not_have_mutable_constants_we_had/?st=JHKIECIJ&sh=e677fc57<|eol|><|eols|><|endoftext|> | 32 |
lolphp | SaraMG | dzj5aol | <|sols|><|sot|>PHP needs mutable constants, and immutable variables, and functions with properties!<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8lrrac/why_does_php_not_have_mutable_constants_we_had/?st=JHKIECIJ&sh=e677fc57<|eol|><|sor|>The real lolphp is that you can change a constant ... wtf.<|eor|><|sor|>You cannot change a constant without installing a third party c extension, literally changing the way the language works.<|eor|><|sor|>Fair enough, but the fact it exists is crazy.<|eor|><|sor|>Its from an extension called runkit. I cant imagine any rational person would use it in production. It makes it possible to modify inheritance, add/rm methods from classes, remove globally defined functions, redefine constants, everything that should never be doable; all during runtime. The people that use this kind of thing are the same ones that eval user input.<|eor|><|soopr|>I wrote runkit, and I endorse this statement.
NEVER USE RUNKIT IN PRODUCTION.
You probably also shouldn't use it in dev.
You probably shouldn't use it.
You shouldn't use it.
Just don't.<|eoopr|><|eols|><|endoftext|> | 16 |
lolphp | tttbbbnnn | dzian46 | <|sols|><|sot|>PHP needs mutable constants, and immutable variables, and functions with properties!<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8lrrac/why_does_php_not_have_mutable_constants_we_had/?st=JHKIECIJ&sh=e677fc57<|eol|><|sor|>The real lolphp is that you can change a constant ... wtf.<|eor|><|sor|>You cannot change a constant without installing a third party c extension, literally changing the way the language works.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | danabrey | dziuigw | <|sols|><|sot|>PHP needs mutable constants, and immutable variables, and functions with properties!<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8lrrac/why_does_php_not_have_mutable_constants_we_had/?st=JHKIECIJ&sh=e677fc57<|eol|><|sor|>Yet more lolbaddeveloper<|eor|><|eols|><|endoftext|> | 13 |
lolphp | _anbuc_ | dzi9ii8 | <|sols|><|sot|>PHP needs mutable constants, and immutable variables, and functions with properties!<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8lrrac/why_does_php_not_have_mutable_constants_we_had/?st=JHKIECIJ&sh=e677fc57<|eol|><|sor|>PHP has a class called ImmutableDate (or something similar) there is a feature, a method called modify. It actually modifies the ImmutableDate in place. IIRC there was also some weird sideeffect happening when you called gettimestamp on it.
This kind of behavior is very usual in PHP, its always a risk and you can rarely trust the language.<|eor|><|sor|>Do you mean [DateTimeImmutable::modify](https://secure.php.net/manual/en/datetimeimmutable.modify.php)?
Because this does _not_ modify the object itself, but returns a new, modified one.
> DateTimeImmutable::modify Creates a new object with modified timestamp
<|eor|><|eols|><|endoftext|> | 12 |
lolphp | tttbbbnnn | dziht0p | <|sols|><|sot|>PHP needs mutable constants, and immutable variables, and functions with properties!<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8lrrac/why_does_php_not_have_mutable_constants_we_had/?st=JHKIECIJ&sh=e677fc57<|eol|><|sor|>The real lolphp is that you can change a constant ... wtf.<|eor|><|sor|>You cannot change a constant without installing a third party c extension, literally changing the way the language works.<|eor|><|sor|>Fair enough, but the fact it exists is crazy.<|eor|><|sor|>Its from an extension called runkit. I cant imagine any rational person would use it in production. It makes it possible to modify inheritance, add/rm methods from classes, remove globally defined functions, redefine constants, everything that should never be doable; all during runtime. The people that use this kind of thing are the same ones that eval user input.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | implicit_cast | dzif48u | <|sols|><|sot|>PHP needs mutable constants, and immutable variables, and functions with properties!<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8lrrac/why_does_php_not_have_mutable_constants_we_had/?st=JHKIECIJ&sh=e677fc57<|eol|><|sor|>What is lolphp about immutable variables? I'd kill for that feature in any language I use that dosen't have it.<|eor|><|sor|>If you get etymologically pedantic enough, "immutable variable" is a contradiction in terms. The key feature of a variable is that it can vary.
An "immutable variable" is better called a "constant."
This discussion is made even more confusing by the ridiculous distinction PHP draws between its 'constant' and 'variable' concepts.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | SaraMG | dzi11qe | <|sols|><|sot|>PHP needs mutable constants, and immutable variables, and functions with properties!<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8lrrac/why_does_php_not_have_mutable_constants_we_had/?st=JHKIECIJ&sh=e677fc57<|eol|><|sor|>What is lolphp about immutable variables? I'd kill for that feature in any language I use that dosen't have it.<|eor|><|soopr|>They're called (runtime) constants.<|eoopr|><|eols|><|endoftext|> | 6 |
lolphp | SaraMG | dzi355s | <|sols|><|sot|>PHP needs mutable constants, and immutable variables, and functions with properties!<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8lrrac/why_does_php_not_have_mutable_constants_we_had/?st=JHKIECIJ&sh=e677fc57<|eol|><|sor|>What is lolphp about immutable variables? I'd kill for that feature in any language I use that dosen't have it.<|eor|><|soopr|>They're called (runtime) constants.<|eoopr|><|sor|>No they are not, constants in PHP are something way way different from an immutable variable.<|eor|><|soopr|>Only in that they have global scope (or they're class constants which aren't runtime settable).
FTR, I agree that I'd like to see something like
final $foo = 'bar';
But you're being a bit of a dick about it. Calm down and enjoy the lolz.<|eoopr|><|eols|><|endoftext|> | 6 |
lolphp | nyamsprod | 7dbdck | <|sols|><|sot|>parse_str is badass ... until you start using it<|eot|><|sol|>https://3v4l.org/dI7KT<|eol|><|eols|><|endoftext|> | 31 |
lolphp | carlos_vini | dpwkupb | <|sols|><|sot|>parse_str is badass ... until you start using it<|eot|><|sol|>https://3v4l.org/dI7KT<|eol|><|sor|>parse_str lacks a good documentation (and a good name...and a good design...). The fact is that it parses the query string just like PHP parses them to turn them into variables. So `.` becomes `_` because dot is not valid in variable names. If you're really interested in parsing query strings try: https://uri.thephpleague.com/5.0/components/query/<|eor|><|eols|><|endoftext|> | 19 |
lolphp | Sarcastinator | dpx32n2 | <|sols|><|sot|>parse_str is badass ... until you start using it<|eot|><|sol|>https://3v4l.org/dI7KT<|eol|><|sor|>A parser function isn't working when you input bogus strings?
What a suprise. /s<|eor|><|sor|>> A parser function isn't working when you input bogus strings?
It does work though. It just soils itself rather than fail.
<|eor|><|eols|><|endoftext|> | 15 |
lolphp | sloat | dpwyreo | <|sols|><|sot|>parse_str is badass ... until you start using it<|eot|><|sol|>https://3v4l.org/dI7KT<|eol|><|sor|>As others have mentioned, it's consistent with what happens with $_REQUEST, $_GET and $_POST because, according to the docs, this function is used to populate those.
The reason why it mangles the names is most probably a holdover from the register_globals days. In fact, the docs warn against using it without the second param because it does register all the query variables in the current scope.
Which is dumb, but it's one of those, "that's just how it is. *SIGH*," type of things. It's not going to change.
The real problem is that PHP lacks any kind of decent abstraction for an HTTP Request. Everything is spread across different super-globals and functions that have no consistent naming. This is why 99/100 people will say use X library to handle it, or you should build your application with Y framework.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | Various_Pickles | dq0yr25 | <|sols|><|sot|>parse_str is badass ... until you start using it<|eot|><|sol|>https://3v4l.org/dI7KT<|eol|><|sor|>A parser function isn't working when you input bogus strings?
What a suprise. /s<|eor|><|sor|>> A parser function isn't working when you input bogus strings?
It does work though. It just soils itself rather than fail.
<|eor|><|sor|>> It does work though. It just soils itself rather than fail.
This is one of, if not the single most succinct descriptions of PHP I have ever seen.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | nyamsprod | dpwhn0z | <|sols|><|sot|>parse_str is badass ... until you start using it<|eot|><|sol|>https://3v4l.org/dI7KT<|eol|><|sor|>A parser function isn't working when you input bogus strings?
What a suprise. /s<|eor|><|soopr|>What part is bogus ?
- Converting `.` on `_` is bogus
- Striping part of the pair key is bogus
- merging key/pair that do not match can also be considered as bogus
... and the list goes on<|eoopr|><|eols|><|endoftext|> | 9 |
lolphp | muffe2k | dpwhi6b | <|sols|><|sot|>parse_str is badass ... until you start using it<|eot|><|sol|>https://3v4l.org/dI7KT<|eol|><|sor|>A parser function isn't working when you input bogus strings?
What a suprise. /s<|eor|><|eols|><|endoftext|> | 6 |
lolphp | DummySarlac | 5p6uw9 | <|sols|><|sot|>Types ? Where we're going, we don't need types.<|eot|><|sol|>https://wiki.php.net/rfc/parameter-no-type-variance<|eol|><|eols|><|endoftext|> | 31 |
lolphp | the_biz | dcowxkd | <|sols|><|sot|>Types ? Where we're going, we don't need types.<|eot|><|sol|>https://wiki.php.net/rfc/parameter-no-type-variance<|eol|><|sor|>this proposal aims to increase the usage of static typing constraints (a good thing!) by eliminating the restriction of adhering to typing constraints (a non sequitor)
the fact that this makes sense worries me...<|eor|><|eols|><|endoftext|> | 27 |
lolphp | kovensky | dcpomsi | <|sols|><|sot|>Types ? Where we're going, we don't need types.<|eot|><|sol|>https://wiki.php.net/rfc/parameter-no-type-variance<|eol|><|sor|>this proposal aims to increase the usage of static typing constraints (a good thing!) by eliminating the restriction of adhering to typing constraints (a non sequitor)
the fact that this makes sense worries me...<|eor|><|sor|>In the specific context it's being used it makes sense. In languages that implement variance/contravariance, function parameters are the one place where contravariance is standard.
This means that, say, on a class hierarchy where you have `U extends T`, it is valid to pretend a function that accepts `T` is a function that accepts `U`. A function that accepts anything (i.e. one without annotations) arguably accepts the supertype of all possible types.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | cleeder | dcpfdng | <|sols|><|sot|>Types ? Where we're going, we don't need types.<|eot|><|sol|>https://wiki.php.net/rfc/parameter-no-type-variance<|eol|><|sor|>While this solves the problem it sets out to solve, it doesn't feel like a very good idea in the end.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | emilvikstrom | dcq7ns9 | <|sols|><|sot|>Types ? Where we're going, we don't need types.<|eot|><|sol|>https://wiki.php.net/rfc/parameter-no-type-variance<|eol|><|sor|>this proposal aims to increase the usage of static typing constraints (a good thing!) by eliminating the restriction of adhering to typing constraints (a non sequitor)
the fact that this makes sense worries me...<|eor|><|sor|>In the specific context it's being used it makes sense. In languages that implement variance/contravariance, function parameters are the one place where contravariance is standard.
This means that, say, on a class hierarchy where you have `U extends T`, it is valid to pretend a function that accepts `T` is a function that accepts `U`. A function that accepts anything (i.e. one without annotations) arguably accepts the supertype of all possible types.<|eor|><|soopr|>First of all, I agree with your arg, no type is the ultimate supertype. But *covariance / contravariance* concepts only can be used, in my opinion, in a fully OOP language. Let me explain my thoughts :
I see the game *covariance / contravariance* as a way to obtain flexibility in classes hierarchies, keeping constraints on function's contracts parameters. As a developer, in daughter class, you know you will not need complete contract required by mother class - eventually because checks are already done -, thus you allow supertype instead of subtype, asking a contract level according to the new environment.
This RFC appears to say : *F.ck contracts, in daughter class, types aren't so important, I prefer pass anything I choose to pass* . I think it's globally dangerous, as classes / functions consumers have to be guided as precisely as possible. Otherwise, provider don't do its job to define a well designed framework for consumers.
TL;DR : I understand the need, but no type check in subfunction is a Pandora Box. Very few developers will guarantee goods API despite of that ; most of us will flood in a sea of bugs.
PS : I hope I didn't write too much bulls.hts, my english is a little bit rusted.<|eoopr|><|sor|>The RFC fits with PHPs nature as a loosely typed language. It doesn't break Liskov's substitution principle: subclasses still implement the contract of their superclass (they accept the same values). So what you are arguing is that subclasses shouldn't be allowed to widen the scope of values they accept, but I seriously don't see why that would be a problem.
In fact, this RFC will give more opportunities to declare types in superclasses in cases where you might want to have subclasses who can accept more values. If someone chooses to widen their scope in a subclass they must do so consciously and also handle the effects of the widened scope, yes. This is a rope you can hang yourself with for sure but it can also be a useful tool. <|eor|><|eols|><|endoftext|> | 5 |
lolphp | Takeoded | 4bvou9 | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|eols|><|endoftext|> | 32 |
lolphp | nikic | d1cyvfk | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|sor|>[deleted]<|eor|><|sor|>> Perfectly valid bug, but I don't suspect someone is going to use a null byte in their password very often. It's possible though, depending on how the function is being used.
It's a perfectly valid bug, but the bug is not in PHP. The bug is in the bcrypt algorithm (or its crypt binding), which a) stops at NUL bytes and b) has a relatively low length limit of 72 (?) characters.
> And this bug is so common in the PHP codebase that the manual actually mentions when a particular function doesn't have it, by calling it "binary safe".
No, it isn't. All PHP functions are "binary safe" unless they rely on external libraries that aren't (*). E.g. functions accepting filesystem paths are generally not binary safe, because the filesystem functions exposed by libc aren't either. Similarly crypt() (and by extension password_hash()) is not binary safe, because the underlying API isn't binary-safe either.
(*) In a standard library with thousands of functions I wouldn't be terribly surprised if there were some cases where NUL bytes aren't supported due to a genuine implementation bug, rather than a 3rd party library limitation. But those cases are definitely not common and if they exist, they should be fixed.<|eor|><|eols|><|endoftext|> | 47 |
lolphp | BilgeXA | d1cz2nz | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|sor|>[deleted]<|eor|><|sor|>> Perfectly valid bug, but I don't suspect someone is going to use a null byte in their password very often. It's possible though, depending on how the function is being used.
It's a perfectly valid bug, but the bug is not in PHP. The bug is in the bcrypt algorithm (or its crypt binding), which a) stops at NUL bytes and b) has a relatively low length limit of 72 (?) characters.
> And this bug is so common in the PHP codebase that the manual actually mentions when a particular function doesn't have it, by calling it "binary safe".
No, it isn't. All PHP functions are "binary safe" unless they rely on external libraries that aren't (*). E.g. functions accepting filesystem paths are generally not binary safe, because the filesystem functions exposed by libc aren't either. Similarly crypt() (and by extension password_hash()) is not binary safe, because the underlying API isn't binary-safe either.
(*) In a standard library with thousands of functions I wouldn't be terribly surprised if there were some cases where NUL bytes aren't supported due to a genuine implementation bug, rather than a 3rd party library limitation. But those cases are definitely not common and if they exist, they should be fixed.<|eor|><|sor|>nikic saves the day by shitting on misinformation once again.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | SituationSoap | d1cxhw1 | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|sor|>[deleted]<|eor|><|soopr|>If I make a user for a script, I might very well have the password be random_bytes(12);
And as for the the "binary safe" thing, I thought that was a relic from the php4 days?<|eoopr|><|sor|>You're creating a password for a user with non printable characters?<|eor|><|sor|>As /u/Takeoded noted, if you're creating users which will only be used by computers via a script of some kind, there's nothing wrong with using non-printable characters in the password for that account.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | RenaKunisaki | d1dbzdr | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|sor|>[deleted]<|eor|><|soopr|>If I make a user for a script, I might very well have the password be random_bytes(12);
And as for the the "binary safe" thing, I thought that was a relic from the php4 days?<|eoopr|><|sor|>How do you think the user is going to type in those 0 bytes generated by random_bytes?<|eor|><|soopr|>i said for "scripts", aka, for COMPUTER ACCOUNTS, to be used by computers, not humans. oh, and check out my new http://en.wikipedia.org account, the username is "R5mcjc6a01houqwq" and the password is "\x30\x30\x5C\xFD\x6A\x00\x0B\xC6\x62\xB8\x4E\x87"<|eoopr|><|sor|>That's the same password I have on my luggage.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | IlikeSalmiakki | d1cv5n6 | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|sor|>[deleted]<|eor|><|soopr|>If I make a user for a script, I might very well have the password be random_bytes(12);
And as for the the "binary safe" thing, I thought that was a relic from the php4 days?<|eoopr|><|sor|>You're creating a password for a user with non printable characters?<|eor|><|eols|><|endoftext|> | 9 |
lolphp | the_alias_of_andrea | d1dkzkd | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|sor|>[deleted]<|eor|><|soopr|>If I make a user for a script, I might very well have the password be random_bytes(12);
And as for the the "binary safe" thing, I thought that was a relic from the php4 days?<|eoopr|><|sor|>You're creating a password for a user with non printable characters?<|eor|><|sor|>As /u/Takeoded noted, if you're creating users which will only be used by computers via a script of some kind, there's nothing wrong with using non-printable characters in the password for that account.<|eor|><|sor|>In theory, this may be true. In practice, systems accepting passwords assume they're human-typable. It's not just null bytes that will cause you trouble here, Unicode normalisation and such might as well.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | Takeoded | d1cup4p | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|sor|>[deleted]<|eor|><|soopr|>If I make a user for a script, I might very well have the password be random_bytes(12);
And as for the the "binary safe" thing, I thought that was a relic from the php4 days?<|eoopr|><|eols|><|endoftext|> | 6 |
lolphp | Takeoded | d1cvkds | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|sor|>[deleted]<|eor|><|soopr|>If I make a user for a script, I might very well have the password be random_bytes(12);
And as for the the "binary safe" thing, I thought that was a relic from the php4 days?<|eoopr|><|sor|>How do you think the user is going to type in those 0 bytes generated by random_bytes?<|eor|><|soopr|>i said for "scripts", aka, for COMPUTER ACCOUNTS, to be used by computers, not humans. oh, and check out my new http://en.wikipedia.org account, the username is "R5mcjc6a01houqwq" and the password is "\x30\x30\x5C\xFD\x6A\x00\x0B\xC6\x62\xB8\x4E\x87"<|eoopr|><|eols|><|endoftext|> | 6 |
lolphp | big_trike | d1fapv6 | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|sor|>[deleted]<|eor|><|soopr|>If I make a user for a script, I might very well have the password be random_bytes(12);
And as for the the "binary safe" thing, I thought that was a relic from the php4 days?<|eoopr|><|sor|>How do you think the user is going to type in those 0 bytes generated by random_bytes?<|eor|><|soopr|>i said for "scripts", aka, for COMPUTER ACCOUNTS, to be used by computers, not humans. oh, and check out my new http://en.wikipedia.org account, the username is "R5mcjc6a01houqwq" and the password is "\x30\x30\x5C\xFD\x6A\x00\x0B\xC6\x62\xB8\x4E\x87"<|eoopr|><|sor|>That's the same password I have on my luggage.<|eor|><|sor|>It must have combination wheels larger than planet Druidia<|eor|><|eols|><|endoftext|> | 6 |
lolphp | Sarcastinator | d1iuh0l | <|sols|><|sot|>in password_ api we can trust...<|eot|><|sol|>https://3v4l.org/7682L<|eol|><|sor|>[deleted]<|eor|><|sor|>> Perfectly valid bug, but I don't suspect someone is going to use a null byte in their password very often. It's possible though, depending on how the function is being used.
It's a perfectly valid bug, but the bug is not in PHP. The bug is in the bcrypt algorithm (or its crypt binding), which a) stops at NUL bytes and b) has a relatively low length limit of 72 (?) characters.
> And this bug is so common in the PHP codebase that the manual actually mentions when a particular function doesn't have it, by calling it "binary safe".
No, it isn't. All PHP functions are "binary safe" unless they rely on external libraries that aren't (*). E.g. functions accepting filesystem paths are generally not binary safe, because the filesystem functions exposed by libc aren't either. Similarly crypt() (and by extension password_hash()) is not binary safe, because the underlying API isn't binary-safe either.
(*) In a standard library with thousands of functions I wouldn't be terribly surprised if there were some cases where NUL bytes aren't supported due to a genuine implementation bug, rather than a 3rd party library limitation. But those cases are definitely not common and if they exist, they should be fixed.<|eor|><|sor|>It's not a bug in bcrypt. Strings in C are by definition 0 terminated. It's a leaky abstraction.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | Rican7 | 4azwzm | <|sols|><|sot|>PHP DateTimeZone offsets work, until they don't<|eot|><|sol|>https://3v4l.org/bEGmb#v5514<|eol|><|eols|><|endoftext|> | 32 |
lolphp | Matt3k | d14yim6 | <|sols|><|sot|>PHP DateTimeZone offsets work, until they don't<|eot|><|sol|>https://3v4l.org/bEGmb#v5514<|eol|><|sor|>I give up. What's the cause? You can only set the timezone once?
EDIT: No, that's not it. I tried many different values, and came back with inconsistent results. One of the more interesting was setting all 3 timezones to EST and I got "12PM, 12PM, 7AM, 2AM" in 5.5.14
Whatever. No idea<|eor|><|eols|><|endoftext|> | 17 |
lolphp | DCoder1337 | d15o0sg | <|sols|><|sot|>PHP DateTimeZone offsets work, until they don't<|eot|><|sol|>https://3v4l.org/bEGmb#v5514<|eol|><|sor|>To fix this, call `getTimestamp()` after setting any timezone that is based on a time offset or abbreviation like CEST (UTC and full names are not affected): https://3v4l.org/KnYdW
----
I would guess the cause of the problem is [here](https://github.com/php/php-src/commit/1394b48d21be3fdc907c28cb450acb8c2b688b65?diff=split#diff-92f1ed1ef7566ec85fbce8bd87bb9267L168), after the *"we need to reset the sse here as unixtime2gmt modifies it"* comment - the old version did the reset all the time, the new version only does it for the named timezones (`sse` here stands for "seconds since epoch").
`DateTimeInterface::getTimestamp()` does some adjusting of the underlying datetime (whoo, *getters modifying the object state*!) that happens to fix this by recalculating `sse`.
----
Fun fact: that adjustment means that `DateTimeImmutable::getTimestamp()` can *mutate the underlying "immutable" object* ([previously discussed here](https://www.reddit.com/r/lolphp/comments/3fhpd0/how_to_modify_datetimeimmutable_call_gettimestamp/)).<|eor|><|eols|><|endoftext|> | 11 |
lolphp | shitbangs | 2io1gl | <|sols|><|sot|>Strange behavior DateInterval in PHP [X-post r/PHP]<|eot|><|sol|>http://stackoverflow.com/q/26258550/250259<|eol|><|eols|><|endoftext|> | 36 |
lolphp | vytah | cl3vfdz | <|sols|><|sot|>Strange behavior DateInterval in PHP [X-post r/PHP]<|eot|><|sol|>http://stackoverflow.com/q/26258550/250259<|eol|><|sor|>>doing a var dump changes the outcome
Wat.
I can't even.
I've lost my ability to can.<|eor|><|eols|><|endoftext|> | 33 |
lolphp | myaut | cl4kydp | <|sols|><|sot|>Strange behavior DateInterval in PHP [X-post r/PHP]<|eot|><|sol|>http://stackoverflow.com/q/26258550/250259<|eol|><|sor|>>doing a var dump changes the outcome
Wat.
I can't even.
I've lost my ability to can.<|eor|><|sor|>> doing a var dump changes the outcome
It's like Schrodinger cat - measurement is changing the outcome.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | merreborn | cl415od | <|sols|><|sot|>Strange behavior DateInterval in PHP [X-post r/PHP]<|eot|><|sol|>http://stackoverflow.com/q/26258550/250259<|eol|><|sor|>What the fuck.
...However, using `>` to compare two objects in a language without operator overloading seems like a bad idea.
At first I thought maybe the object was implicitly being cast to a string, and the strings compared, but trying to cast a dateinterval to a string results in `Object of class DateInterval could not be converted to string`. So it's not string comparison. What exactly happens when you use an inequality comparison operator on two objects in PHP?
This is interesting: http://3v4l.org/jLSDU
1. HHVM doesn't replicate this bug
1. In all cases, the objects start out equal
1. In non-HHVM PHP, after the read-with-side-effects, the objects become inequal
Hm. I guess the object returned by createFromDateString is lazily evaluated in some way?<|eor|><|eols|><|endoftext|> | 7 |
lolphp | shitbangs | cl4li9h | <|sols|><|sot|>Strange behavior DateInterval in PHP [X-post r/PHP]<|eot|><|sol|>http://stackoverflow.com/q/26258550/250259<|eol|><|sor|>>doing a var dump changes the outcome
Wat.
I can't even.
I've lost my ability to can.<|eor|><|sor|>> doing a var dump changes the outcome
It's like Schrodinger cat - measurement is changing the outcome.<|eor|><|soopr|>I was thinking of the double slit experiment, but [r/php seems to disagree](http://www.reddit.com/r/PHP/comments/2inrls/why_does_var_dump_change_the_results_of_comparing/cl3t8q0)
lol<|eoopr|><|eols|><|endoftext|> | 6 |
lolphp | eviljames | 2eavr4 | <|soss|><|sot|>Something snarky for you folks to post.<|eot|><|sost|>http://www.reddit.com/r/awesomephp is a thing. As long as I moderate it, it will not change from its state today :)<|eost|><|eoss|><|endoftext|> | 32 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.