subreddit
stringclasses
7 values
author
stringlengths
3
20
id
stringlengths
5
7
content
stringlengths
67
30.4k
score
int64
0
140k
lolphp
cythrawll
cgcxpvg
<|sols|><|sot|>htmlentities only displays an error when display_errors is off<|eot|><|sol|>http://insomanic.me.uk/post/191397106/php-htmlspecialchars-htmlentities-invalid<|eol|><|soopr|>Don't worry though, [it's intentional](https://bugs.php.net/bug.php?id=47494)!<|eoopr|><|sor|>I have no words. <|eor|><|soopr|>Mine was a muted "Fuck." This will be my last PHP project. There is a code freeze in two weeks, and I'm out in a month (internship). Between that and PDO refusing to throw exceptions, I have given up. I just work on making the next guy's job easier.<|eoopr|><|sor|>> PDO refusing to throw exceptions What's up there? Don't you just set PDO to throw exceptions and forget about it?<|eor|><|soopr|>Only when it works. There are a few matching bug reports on PHP.net, but all of them seem abandonned, as is dblib. http://stackoverflow.com/questions/22486004/pdo-setattribute-has-no-effect-with-dblib-and-sql-server<|eoopr|><|sor|>Your problem is using dblib. Which is horrible. You really should use the sqlsrv pdo driver from microsoft.<|eor|><|soopr|>You mean the one that doesn't run on Linux?<|eoopr|><|sor|>Here's how to connect to MS SQL from any language on Linux: don't. Microsoft has put almost no effort into linux/mac clients. If you absolutely have to, or you cant figure out how to sync the data to a more interoperable data store. Then microsoft offers an odbc driver. Which still sucks.. But its the best they've offered. Absolutely under no circumstance is dblib and freetds a solution. Even the authors will tell you that. They never ever really got out of alpha stage as the entire project had to be reverse engineered without any help from microsoft. the presence of drivers for it in languages arose out of desperation. And when ms finally came out with an odbc solution. It pretty much became abandoned.<|eor|><|eols|><|endoftext|>
11
lolphp
Wompuz
t35bj
<|sols|><|sot|>HORSE<|eot|><|sol|>http://i.imgur.com/1zgFd.jpg<|eol|><|eols|><|endoftext|>
58
lolphp
mestore
c4j4xok
<|sols|><|sot|>HORSE<|eot|><|sol|>http://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I know the community gives php a lot of hate, and 'horse' should never be returned. But let us be honest here, if you code like that, whose fault is it really? (I think the proper shorthand in php is to wrap each layer in parens)<|eor|><|eols|><|endoftext|>
23
lolphp
mofrodo
c4j672h
<|sols|><|sot|>HORSE<|eot|><|sol|>http://i.imgur.com/1zgFd.jpg<|eol|><|sor|>There is nothing wrong with this statement. The first condition is true, which returns the string 'CAR', which also equals to TRUE, which in turn returns 'HORSE'. But anyway, if you code like this, you're a moron.<|eor|><|eols|><|endoftext|>
11
lolphp
mostrandomguy
2tpxc9
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|eols|><|endoftext|>
63
lolphp
deadstone
co1ckl7
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|sor|><|eor|><|sor|>> This has been beaten to death a hundreds of times; php's type coercion when using == is insane, and you should never use ==. Except this is worse. `"6 Chickens" + "4 Geese" === 10` will still evaluate as true.<|eor|><|eols|><|endoftext|>
32
lolphp
HiddenKrypt
co1sw2h
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|sor|>Ahh, a prime example of "is a" inheritance. See, PHP is smart enough to know that geese and chickens are both birds!<|eor|><|eols|><|endoftext|>
16
lolphp
quenoz
co1fa8u
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|sor|>I can simulate this behavior in C++11: http://ideone.com/2lZEWd Now chickens are statically typed ;)<|eor|><|sor|>See, in php you don't need all those preparations, php > c++ confirmed. /s<|eor|><|eols|><|endoftext|>
15
lolphp
myaut
co1c41j
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|sor|>I can simulate this behavior in C++11: http://ideone.com/2lZEWd Now chickens are statically typed ;)<|eor|><|eols|><|endoftext|>
14
lolphp
Sgeo
co1el3a
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|sor|>Why does this work? Does php just automatically convert the strings to numbers? What if you want to compare strings?<|eor|><|sor|>Always use ===<|eor|><|sor|>See other comments in thread.<|eor|><|eols|><|endoftext|>
10
lolphp
InconsiderateBastard
co20swo
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|sor|><|eor|><|sor|>> This has been beaten to death a hundreds of times; php's type coercion when using == is insane, and you should never use ==. Except this is worse. `"6 Chickens" + "4 Geese" === 10` will still evaluate as true.<|eor|><|sor|>No, because + is an implicit conversion to int.<|eor|><|sor|>Unless the string holds something that's too big to be an int, in which case its made into a float instead.<|eor|><|eols|><|endoftext|>
10
lolphp
ZiggyTheHamster
co202cf
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|sor|><|eor|><|sor|>> This has been beaten to death a hundreds of times; php's type coercion when using == is insane, and you should never use ==. Except this is worse. `"6 Chickens" + "4 Geese" === 10` will still evaluate as true.<|eor|><|sor|>No, because + is an implicit conversion to int.<|eor|><|sor|>Is there an operator that can be used instead to prevent coercion? A flag that only allows strictly obvious coercion (i.e., `"5" = 5`, but `"1234 Five" != 1234`)?<|eor|><|sor|>Yes... `===`<|eor|><|sor|> php > var_dump("5" + "5 and some other garbage that should break this equation" === 10); bool(true) Am I missing something here?<|eor|><|eols|><|endoftext|>
10
lolphp
barubary
co2cfbz
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|sor|>Oh God, I've had a few times where I've used `+` instead of `.` and spent hours trying to track down the bug, since `+` is basically the standard string concatenation operator in almost every language ever.<|eor|><|sor|>> \+ is basically the standard string concatenation operator in almost every language ever String concatenation: * Python, JavaScript, Pascal: `+` * Perl, PHP: `.` * C: no such thing (except maybe `strcat`?) * Scheme: `string-append` * Common Lisp: `(concatenate 'string x y)` * Tcl: no operator, just `"$x$y"` * Haskell: `++` * Ocaml, SML: `^` * Visual Basic: `&` * SQL: `||` * awk: no operator, just juxtaposition * Fortran: `//`<|eor|><|eols|><|endoftext|>
9
lolphp
Various_Pickles
co26uf0
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|sor|>Although, yes, this is an ancient and well-known *feature* of PHP, I despise the fact that people try to explain it away as "type coercion". Type coercion is perfectly acceptable (and wonderful) in situations such as auto-boxing, 1:1 parsing, etc, but, a rule of "if a string starts with something that looks like a number, ignore the rest of it and try and make it a number (silently fail if unsuccessful because potato)", is pure batshit insanity.<|eor|><|eols|><|endoftext|>
8
lolphp
hipsterhacker
co3ef1s
<|sols|><|sot|>if ("6 Chickens" + "4 Geese" == "10 Birds")<|eot|><|sol|>http://codepad.org/Ctwy50Nk<|eol|><|sor|>Oh God, I've had a few times where I've used `+` instead of `.` and spent hours trying to track down the bug, since `+` is basically the standard string concatenation operator in almost every language ever.<|eor|><|sor|>> \+ is basically the standard string concatenation operator in almost every language ever String concatenation: * Python, JavaScript, Pascal: `+` * Perl, PHP: `.` * C: no such thing (except maybe `strcat`?) * Scheme: `string-append` * Common Lisp: `(concatenate 'string x y)` * Tcl: no operator, just `"$x$y"` * Haskell: `++` * Ocaml, SML: `^` * Visual Basic: `&` * SQL: `||` * awk: no operator, just juxtaposition * Fortran: `//`<|eor|><|sor|>Java, C++, Ruby, Scala: `+`<|eor|><|eols|><|endoftext|>
8
lolphp
ealf
1wgrc6
<|sols|><|sot|>That preg_replace('/(.+)/e', 'foo("$1")') construct that got eBay hacked over a month ago (and Yahoo this week)? The official documentation still uses it as an example.<|eot|><|sol|>http://php.net/preg_replace<|eol|><|eols|><|endoftext|>
63
lolphp
ealf
cf1sfgp
<|sols|><|sot|>That preg_replace('/(.+)/e', 'foo("$1")') construct that got eBay hacked over a month ago (and Yahoo this week)? The official documentation still uses it as an example.<|eot|><|sol|>http://php.net/preg_replace<|eol|><|soopr|>> When using the deprecated e modifier, this function escapes some characters (namely ', ", \ and NULL) in the strings that replace the backreferences. This is done to ensure that no syntax errors arise from backreference usage with either single or double quotes (e.g. 'strlen(\'$1\')+strlen("$2")'). ... and no mention that they forgot to escape `${}` and that the whole thing allows executing arbitrary code (and yes, also "syntax errors", if that's how far your imagination goes) EDIT: They've added "see ((link)) for additional information about security risks" *to the changelog two screens down* where everyone will see it.<|eoopr|><|eols|><|endoftext|>
20
lolphp
ealf
cf24j54
<|sols|><|sot|>That preg_replace('/(.+)/e', 'foo("$1")') construct that got eBay hacked over a month ago (and Yahoo this week)? The official documentation still uses it as an example.<|eot|><|sol|>http://php.net/preg_replace<|eol|><|sor|>Links for where this was used to hack those sites?<|eor|><|soopr|>http://www.secalert.net/2013/12/13/ebay-remote-code-execution/ http://www.sec-down.com/wordpress/?p=87<|eoopr|><|eols|><|endoftext|>
11
lolphp
PasswordIsntHAMSTER
cf1trdk
<|sols|><|sot|>That preg_replace('/(.+)/e', 'foo("$1")') construct that got eBay hacked over a month ago (and Yahoo this week)? The official documentation still uses it as an example.<|eot|><|sol|>http://php.net/preg_replace<|eol|><|sor|>Example #2 completely baffles my mind.<|eor|><|eols|><|endoftext|>
8
lolphp
dehrmann
cf27q69
<|sols|><|sot|>That preg_replace('/(.+)/e', 'foo("$1")') construct that got eBay hacked over a month ago (and Yahoo this week)? The official documentation still uses it as an example.<|eot|><|sol|>http://php.net/preg_replace<|eol|><|soopr|>> When using the deprecated e modifier, this function escapes some characters (namely ', ", \ and NULL) in the strings that replace the backreferences. This is done to ensure that no syntax errors arise from backreference usage with either single or double quotes (e.g. 'strlen(\'$1\')+strlen("$2")'). ... and no mention that they forgot to escape `${}` and that the whole thing allows executing arbitrary code (and yes, also "syntax errors", if that's how far your imagination goes) EDIT: They've added "see ((link)) for additional information about security risks" *to the changelog two screens down* where everyone will see it.<|eoopr|><|sor|>Why does this remind me of magic strings?<|eor|><|eols|><|endoftext|>
7
lolphp
_vec_
cf1y862
<|sols|><|sot|>That preg_replace('/(.+)/e', 'foo("$1")') construct that got eBay hacked over a month ago (and Yahoo this week)? The official documentation still uses it as an example.<|eot|><|sol|>http://php.net/preg_replace<|eol|><|sor|>Example #2 completely baffles my mind.<|eor|><|sor|>Seriously. What's up with that?<|eor|><|sor|>PHP arrays are also hashes, and hash keys are ordered in insertion order (except for when they're not; this is PHP after all). $test = array( 3 => 'three', 2 => 'two', 1 => 'one' ); foreach ($test as $num) print "$num..."; print "liftoff!"; prints "three...two...one...liftoff!"<|eor|><|eols|><|endoftext|>
7
lolphp
seventoes
cf1vwqe
<|sols|><|sot|>That preg_replace('/(.+)/e', 'foo("$1")') construct that got eBay hacked over a month ago (and Yahoo this week)? The official documentation still uses it as an example.<|eot|><|sol|>http://php.net/preg_replace<|eol|><|sor|>Example #2 completely baffles my mind.<|eor|><|sor|>Seriously. What's up with that?<|eor|><|eols|><|endoftext|>
5
lolphp
Serialk
1asgn4
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|eols|><|endoftext|>
58
lolphp
scshunt
c90cykm
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|sor|>Apparently there was no issue with \ and escape sequences, though.<|eor|><|eols|><|endoftext|>
20
lolphp
vytah
c90icnx
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|sor|>PHP parsing and lexing is just a nightmare.<|eor|><|sor|>PHP is only lexed, it's not parsed. The interpreted emits opcodes directly from a flat stream of lexemes, often having to go back and modify what it has already emitted.<|eor|><|eols|><|endoftext|>
20
lolphp
dipswitch
c90x4uj
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|sor|>PHP parsing and lexing is just a nightmare.<|eor|><|sor|>PHP is only lexed, it's not parsed. The interpreted emits opcodes directly from a flat stream of lexemes, often having to go back and modify what it has already emitted.<|eor|><|sor|>How the fuck does it handle operator precedence and parentheses?<|eor|><|sor|>[Hint](http://eval.in/492)<|eor|><|eols|><|endoftext|>
14
lolphp
Serialk
c90d0vq
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|soopr|>It is worth noting that I found this via this RFC : https://wiki.php.net/rfc/namespaceseparator which gives the choice between seven completely inconsistant ASCII sequences as namespace separators. However this RFC is used to argue the fact that the choice of the \ was "probably the only sane option." (http://fabien.potencier.org/article/64/php-is-much-better-than-you-think , comment #18)<|eoopr|><|eols|><|endoftext|>
11
lolphp
cythrawll
c90dvm1
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|sor|>PHP parsing and lexing is just a nightmare.<|eor|><|eols|><|endoftext|>
10
lolphp
chellomere
c9a8649
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|sor|>PHP: a language dictated by what a lexer can do.<|eor|><|eols|><|endoftext|>
8
lolphp
vsync
c90tnd0
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|sor|>> With the new implementation and no blocks, many people expected one namespace per file. > Since fewer files means faster execution, many people simply concatenate PHP scripts. Their expectation Couldn't read (or even skim) any more. So very much wrong with all of this.<|eor|><|eols|><|endoftext|>
8
lolphp
Packet_Ranger
c90r2vw
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|soopr|>It is worth noting that I found this via this RFC : https://wiki.php.net/rfc/namespaceseparator which gives the choice between seven completely inconsistant ASCII sequences as namespace separators. However this RFC is used to argue the fact that the choice of the \ was "probably the only sane option." (http://fabien.potencier.org/article/64/php-is-much-better-than-you-think , comment #18)<|eoopr|><|sor|>If you want to laugh particularly hard, look at the 'objective' weighting they apply. Because they didn't actually use anyone who understands how these systems should work they overly relied upon 'number of chars'. Giving '/' a 2 point bonus over every other option, despite being only one character shorter. They also assign different values the typeability of characters rather arbitrarily. Basically, it was a hilarious mess, and modern PHP is made even worse due to their incompetence.<|eor|><|sor|>oh my god! >not in line with current PHP ***synthax***. <|eor|><|sor|>[This is a Synthaxe](https://en.wikipedia.org/wiki/File:SynthAxe.jpg). And it bears as much resemblance to a guitar, as PHP does to a programming language.<|eor|><|eols|><|endoftext|>
8
lolphp
hahainternet
c90f4e7
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|soopr|>It is worth noting that I found this via this RFC : https://wiki.php.net/rfc/namespaceseparator which gives the choice between seven completely inconsistant ASCII sequences as namespace separators. However this RFC is used to argue the fact that the choice of the \ was "probably the only sane option." (http://fabien.potencier.org/article/64/php-is-much-better-than-you-think , comment #18)<|eoopr|><|sor|>If you want to laugh particularly hard, look at the 'objective' weighting they apply. Because they didn't actually use anyone who understands how these systems should work they overly relied upon 'number of chars'. Giving '/' a 2 point bonus over every other option, despite being only one character shorter. They also assign different values the typeability of characters rather arbitrarily. Basically, it was a hilarious mess, and modern PHP is made even worse due to their incompetence.<|eor|><|eols|><|endoftext|>
6
lolphp
Sheepshow
c90mm9r
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|soopr|>It is worth noting that I found this via this RFC : https://wiki.php.net/rfc/namespaceseparator which gives the choice between seven completely inconsistant ASCII sequences as namespace separators. However this RFC is used to argue the fact that the choice of the \ was "probably the only sane option." (http://fabien.potencier.org/article/64/php-is-much-better-than-you-think , comment #18)<|eoopr|><|sor|>If you want to laugh particularly hard, look at the 'objective' weighting they apply. Because they didn't actually use anyone who understands how these systems should work they overly relied upon 'number of chars'. Giving '/' a 2 point bonus over every other option, despite being only one character shorter. They also assign different values the typeability of characters rather arbitrarily. Basically, it was a hilarious mess, and modern PHP is made even worse due to their incompetence.<|eor|><|sor|>I laughed out loud at their metrics: > `+1` means "not negative" > `-+0` means "not very negative" (presumably in php `-+0 != +0 != -0 != +-0 != 0` ) > `-1` means "very negative"<|eor|><|eols|><|endoftext|>
6
lolphp
poizan42
c920108
<|sols|><|sot|>"Because an inconsistency between namespace separator '::' and ternary operator's ':' could not be solved, namespace were finally removed."<|eot|><|sol|>https://wiki.php.net/rfc/namespacecurlies<|eol|><|sor|>PHP parsing and lexing is just a nightmare.<|eor|><|sor|>PHP is only lexed, it's not parsed. The interpreted emits opcodes directly from a flat stream of lexemes, often having to go back and modify what it has already emitted.<|eor|><|sor|>How the fuck does it handle operator precedence and parentheses?<|eor|><|sor|>[Hint](http://eval.in/492)<|eor|><|sor|>> OK (0.004 sec real, 0.117 sec wall, 13 MB, **94 syscalls**) wat<|eor|><|eols|><|endoftext|>
5
lolphp
ScriptFUSION
7z5bcq
<|soss|><|sot|>"last week" relative date is special cased<|eot|><|sost|>"Last year", "last month", "last day", "last hour", etc. all take the current date and subtract the specified period. So `last year` would be February 21^st, 2017 if executed on the date of this post. What about "last week"? Surely it would be seven days ago, Valentines Day, February 14^th, right? Nope. *Last week* is special cased with an implied `Monday` prefix, so it becomes "Monday last week", is hard locked to Monday, and will evaluate to February 12^th. Thanks PHP <|eost|><|eoss|><|endoftext|>
59
lolphp
ScriptFUSION
dulm5br
<|soss|><|sot|>"last week" relative date is special cased<|eot|><|sost|>"Last year", "last month", "last day", "last hour", etc. all take the current date and subtract the specified period. So `last year` would be February 21^st, 2017 if executed on the date of this post. What about "last week"? Surely it would be seven days ago, Valentines Day, February 14^th, right? Nope. *Last week* is special cased with an implied `Monday` prefix, so it becomes "Monday last week", is hard locked to Monday, and will evaluate to February 12^th. Thanks PHP <|eost|><|sor|>It makes sense though: - Last year: It's this way because you can't just always subtract 365 days so it makes sense that this literally just removes a full year. - Last week: There is a universal way to get last week, it's `-7 days`, but there is no way to get the start of last week so this is probably why it's set up this way.<|eor|><|soopr|>You could argue anything makes sense with logic that airtight.<|eoopr|><|eoss|><|endoftext|>
20
lolphp
eztab
dulyh8k
<|soss|><|sot|>"last week" relative date is special cased<|eot|><|sost|>"Last year", "last month", "last day", "last hour", etc. all take the current date and subtract the specified period. So `last year` would be February 21^st, 2017 if executed on the date of this post. What about "last week"? Surely it would be seven days ago, Valentines Day, February 14^th, right? Nope. *Last week* is special cased with an implied `Monday` prefix, so it becomes "Monday last week", is hard locked to Monday, and will evaluate to February 12^th. Thanks PHP <|eost|><|sor|>It makes sense though: - Last year: It's this way because you can't just always subtract 365 days so it makes sense that this literally just removes a full year. - Last week: There is a universal way to get last week, it's `-7 days`, but there is no way to get the start of last week so this is probably why it's set up this way.<|eor|><|sor|>So there should be "last Monday" but no "last week" working completely different than last year.<|eor|><|eoss|><|endoftext|>
8
lolphp
jesseschalken
duzidlq
<|soss|><|sot|>"last week" relative date is special cased<|eot|><|sost|>"Last year", "last month", "last day", "last hour", etc. all take the current date and subtract the specified period. So `last year` would be February 21^st, 2017 if executed on the date of this post. What about "last week"? Surely it would be seven days ago, Valentines Day, February 14^th, right? Nope. *Last week* is special cased with an implied `Monday` prefix, so it becomes "Monday last week", is hard locked to Monday, and will evaluate to February 12^th. Thanks PHP <|eost|><|sor|>If you have any expectations about the result of `strtotime()`, you're going to have a bad time.<|eor|><|eoss|><|endoftext|>
7
lolphp
ScriptFUSION
dumaelf
<|soss|><|sot|>"last week" relative date is special cased<|eot|><|sost|>"Last year", "last month", "last day", "last hour", etc. all take the current date and subtract the specified period. So `last year` would be February 21^st, 2017 if executed on the date of this post. What about "last week"? Surely it would be seven days ago, Valentines Day, February 14^th, right? Nope. *Last week* is special cased with an implied `Monday` prefix, so it becomes "Monday last week", is hard locked to Monday, and will evaluate to February 12^th. Thanks PHP <|eost|><|sor|>It makes sense though: - Last year: It's this way because you can't just always subtract 365 days so it makes sense that this literally just removes a full year. - Last week: There is a universal way to get last week, it's `-7 days`, but there is no way to get the start of last week so this is probably why it's set up this way.<|eor|><|sor|>So there should be "last Monday" but no "last week" working completely different than last year.<|eor|><|soopr|>There's always the *explicit* "Monday last week". There seems to be no reason why "last week" adopts the *implied* Monday prefix.<|eoopr|><|eoss|><|endoftext|>
7
lolphp
defiante1
3fhpd0
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|eols|><|endoftext|>
61
lolphp
livid_taco
ctopd7a
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>PHP Quantum physics again; introspecting something changes it's value. ^(Not my joke, found it somewhere here)<|eor|><|eols|><|endoftext|>
30
lolphp
midir
ctouclt
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>PHP Quantum physics again; introspecting something changes it's value. ^(Not my joke, found it somewhere here)<|eor|><|sor|>Your reddit account appears to be [shadowbanned](/r/shadowban).<|eor|><|eols|><|endoftext|>
18
lolphp
jrh3k5
ctot7lb
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>What baffles me even more is the fact that apparently there is a class `DateTimeImmutable`, which kind of implies that the "regular" date/time type is mutable. Why would one ever want a mutable date/time class?<|eor|><|sor|>Java suffers from the same sin with java.util.Date.<|eor|><|eols|><|endoftext|>
15
lolphp
tdammers
ctosz2y
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>What baffles me even more is the fact that apparently there is a class `DateTimeImmutable`, which kind of implies that the "regular" date/time type is mutable. Why would one ever want a mutable date/time class?<|eor|><|eols|><|endoftext|>
14
lolphp
jrh3k5
ctovayc
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>What baffles me even more is the fact that apparently there is a class `DateTimeImmutable`, which kind of implies that the "regular" date/time type is mutable. Why would one ever want a mutable date/time class?<|eor|><|sor|>Java suffers from the same sin with java.util.Date.<|eor|><|sor|>Hmm, let's file this under "Fallacies of Overly Naive Object-Oriented Design", shall we?<|eor|><|sor|>Perhaps "premature optimization of memory usage patterns"? In Java's case, anyway.<|eor|><|eols|><|endoftext|>
11
lolphp
ThisIsADogHello
ctoyjbz
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>PHP Quantum physics again; introspecting something changes it's value. ^(Not my joke, found it somewhere here)<|eor|><|sor|>Your reddit account appears to be [shadowbanned](/r/shadowban).<|eor|><|sor|>Looks like they fixed it. He appears to just be regular banned now.<|eor|><|eols|><|endoftext|>
10
lolphp
tdammers
ctouia7
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>What baffles me even more is the fact that apparently there is a class `DateTimeImmutable`, which kind of implies that the "regular" date/time type is mutable. Why would one ever want a mutable date/time class?<|eor|><|sor|>Java suffers from the same sin with java.util.Date.<|eor|><|sor|>Hmm, let's file this under "Fallacies of Overly Naive Object-Oriented Design", shall we?<|eor|><|eols|><|endoftext|>
9
lolphp
Schmittfried
ctp7aq9
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>Don't forget DateTimeImmutable.Modify(). IIRC it returns a new instance of DateTimeImmutable, and exists so the API matches DateTime (mutable), but that doesn't make it right!<|eor|><|sor|>Wait, what? Isn't that how immutable objects work, by returning a new instance when you call a traditionally mutating function on it? I mean I'm no expert but that's exactly what Clojure's sequence-appending functions do.<|eor|><|sor|>Yes, but the point is the ridiculous name.<|eor|><|eols|><|endoftext|>
8
lolphp
greenthumble
ctp5u04
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>Don't forget DateTimeImmutable.Modify(). IIRC it returns a new instance of DateTimeImmutable, and exists so the API matches DateTime (mutable), but that doesn't make it right!<|eor|><|sor|>Wait, what? Isn't that how immutable objects work, by returning a new instance when you call a traditionally mutating function on it? I mean I'm no expert but that's exactly what Clojure's sequence-appending functions do.<|eor|><|eols|><|endoftext|>
7
lolphp
poizan42
ctpklgu
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>PHP Quantum physics again; introspecting something changes it's value. ^(Not my joke, found it somewhere here)<|eor|><|sor|>Your reddit account appears to be [shadowbanned](/r/shadowban).<|eor|><|sor|>Looks like they fixed it. He appears to just be regular banned now.<|eor|><|sor|>I recently read that they were to never shadowban ordinary users ever again, if I understood that correctly.<|eor|><|sor|>The admins have several times said that shadowbans would only ever be used for spammers. And they have several times shown not to keep that promise (e.g. using shadowbans on vote manipulators instead of just regular banning them).<|eor|><|eols|><|endoftext|>
7
lolphp
HildartheDorf
ctot6hs
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>Don't forget DateTimeImmutable.Modify(). IIRC it returns a new instance of DateTimeImmutable, and exists so the API matches DateTime (mutable), but that doesn't make it right!<|eor|><|eols|><|endoftext|>
6
lolphp
tdammers
ctovbxi
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>What baffles me even more is the fact that apparently there is a class `DateTimeImmutable`, which kind of implies that the "regular" date/time type is mutable. Why would one ever want a mutable date/time class?<|eor|><|sor|>Java suffers from the same sin with java.util.Date.<|eor|><|sor|>Hmm, let's file this under "Fallacies of Overly Naive Object-Oriented Design", shall we?<|eor|><|sor|>Perhaps "premature optimization of memory usage patterns"? In Java's case, anyway.<|eor|><|sor|>My guess would have been "not giving (im)mutability any thought whatsoever", but I'm willing to grant benefit of the doubt here.<|eor|><|eols|><|endoftext|>
6
lolphp
gearvOsh
ctp4cbx
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>What baffles me even more is the fact that apparently there is a class `DateTimeImmutable`, which kind of implies that the "regular" date/time type is mutable. Why would one ever want a mutable date/time class?<|eor|><|sor|>So that you can modify the date: `$date->modify('+1 hour');`. All of PHP is mutable, so very rarely do you actually see something immutable.<|eor|><|eols|><|endoftext|>
5
lolphp
tdammers
ctp6pa9
<|sols|><|sot|>How to modify DateTimeImmutable? Call getTimestamp() on it.<|eot|><|sol|>https://bugs.php.net/bug.php?id=67634<|eol|><|sor|>What baffles me even more is the fact that apparently there is a class `DateTimeImmutable`, which kind of implies that the "regular" date/time type is mutable. Why would one ever want a mutable date/time class?<|eor|><|sor|>So that you can modify the date: `$date->modify('+1 hour');`. All of PHP is mutable, so very rarely do you actually see something immutable.<|eor|><|sor|>Not all is immutable - integers for example are not. And just like there is nothing to modify about the number 23, a point-in-time is also conceptually immutable: it's not like you can say "from now on, the month in the date of April 22nd 2015 shall be May" and make sense to anyone. It does make sense to take a variable that contains a date, and assign it a different date, just like it makes sense to put the number 7 into a variable that previously contained the number 23, but the numbers themselves are immutable, and dates should ideally behave the same way, because that makes sense. It's not like someone sat down and said, "mutable objects are a darn good idea, they make for very good and maintainable software, let's make everything mutable objects" - things are mutable in PHP because whoever designed them didn't think any further than the next few hours, and being able to change the month part of a date value in-place seemed like a useful thing, and it works great, except that objects (including datetime objects) are reference types in PHP, and so many variables in largely unrelated parts of your codebase can end up containing the same object, and changing its month component in one of them changes it in all of them, and then all hell bursts loose and you rip your hair out, and then when you realize what happened you decide that you need to be more defensive about your dates, and you start making copies of them all over the place which makes your code butt-ugly, despite the fact that mutable date/time objects were supposed to make your life easier. function foobar(DateTime $targetDate) { $beginDate = $targetDate->clone(); $beginDate->addMonths(-1); $endDate = $beginDate->clone(); $endDate->addMonths(1); return someOtherFunction($beginDate, $endDate); } // when really your life could be as simple as: function foobar(DateTime $targetDate) { return someOtherFunction($targetDate->addMonths(-1), $targetDate->addMonths(1)); } // or, if PHP were actually completely sensible about // itself: function foobar(DateTime $targetDate) { return someOtherFunction($targetDate - months(1), $targetDate + months(1)); } <|eor|><|eols|><|endoftext|>
5
lolphp
andsens
2tywp9
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|eols|><|endoftext|>
62
lolphp
callcifer
co3ocln
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>In true PHP fashion, to parse ini strings in a non-retarded way you need to do this: parse_ini_string($str, false, INI_SCANNER_RAW);<|eor|><|eols|><|endoftext|>
23
lolphp
andsens
co3v9u4
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>Actually `"no"==false` and `"yes"==true, but "" and "1" is what you get if you convert them to strings. php -r "var_dump(false.'');" string(0) "" php -r "var_dump(true.'');" string(1) "1" php -r "var_dump(true=='1');" bool(true) php -r "var_dump(false=='');" bool(true) <|eor|><|soopr|>Actually no. If `parse_ini_*` returned booleans there would be at least some sense to this madness. PHP `parse_ini_*` converts the 'yes' and 'no' settings from strings into booleans and coerces the resulting values back into strings.<|eoopr|><|eols|><|endoftext|>
19
lolphp
callcifer
co4efbh
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>I don't understand the problem with this one... seems fairly intuitive to me. Can someone explain what I'm missing?<|eor|><|sor|>You are reading key value pairs from an ini line where the values are country codes. This works fine for most countries but when PHP encounters Norway ("no"), it converts it to an empty string. So if you want to read what was actually in the ini (you know, what you were trying to do in the first place), you have to do this: parse_ini_string($str, false, INI_SCANNER_RAW); This is yet another example of PHP's stdlib being "broken by default, works with extra params".<|eor|><|eols|><|endoftext|>
18
lolphp
gearvOsh
co3q1zi
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>Actually `"no"==false` and `"yes"==true, but "" and "1" is what you get if you convert them to strings. php -r "var_dump(false.'');" string(0) "" php -r "var_dump(true.'');" string(1) "1" php -r "var_dump(true=='1');" bool(true) php -r "var_dump(false=='');" bool(true) <|eor|><|sor|> > Actually "no"==false and `"yes"==true For real? <|eor|><|sor|>When it's an INI setting, yes.<|eor|><|eols|><|endoftext|>
16
lolphp
bart2019
co3l4gn
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>Actually `"no"==false` and `"yes"==true, but "" and "1" is what you get if you convert them to strings. php -r "var_dump(false.'');" string(0) "" php -r "var_dump(true.'');" string(1) "1" php -r "var_dump(true=='1');" bool(true) php -r "var_dump(false=='');" bool(true) <|eor|><|eols|><|endoftext|>
15
lolphp
andsens
co3vfk8
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>In true PHP fashion, to parse ini strings in a non-retarded way you need to do this: parse_ini_string($str, false, INI_SCANNER_RAW);<|eor|><|soopr|>That's what I ended up doing. It's funny how whatever you think the sane default for a PHP setting is, it's the exact opposite - one can almost use it as a rule of thumb. Much like how PDO per default swallows errors and you have to configure it to throw exceptions.<|eoopr|><|eols|><|endoftext|>
13
lolphp
memoryspaceglitch
co3qn06
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>Wait, how do you do if you're norwegian?<|eor|><|eols|><|endoftext|>
12
lolphp
callcifer
co4uvue
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>In true PHP fashion, to parse ini strings in a non-retarded way you need to do this: parse_ini_string($str, false, INI_SCANNER_RAW);<|eor|><|soopr|>That's what I ended up doing. It's funny how whatever you think the sane default for a PHP setting is, it's the exact opposite - one can almost use it as a rule of thumb. Much like how PDO per default swallows errors and you have to configure it to throw exceptions.<|eoopr|><|sor|>PHP target development is quick and accessible. If you know enough about programming to be an expert then you can configure expert settings. Yes, that can lead to some esoteric issues which may not be thought out well, and yes there are still legacy issues which could fairly easily be mitigated by default namespaces, but, really, in the end, I'm glad PHP does exist at least for an agile project development or small organizations.<|eor|><|sor|>> If you know enough about programming to be an expert then you can configure expert settings. How is "reading a value from an ini" in any way an *expert setting*? The fact that this is broken-by-default is *atrocious*.<|eor|><|eols|><|endoftext|>
12
lolphp
andsens
co3uxuf
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|soopr|>I thought I was going insane, because somehow the standard language was fine with being anything else but norwegian. When you're up to your neck in various sql statements that cannot be prepared because some string is empty, you can't see the forest for the trees. It's only because I recently worked on some ansible (written in yaml) that I realized 'no' can actually mean the boolean false.<|eoopr|><|eols|><|endoftext|>
11
lolphp
ConcernedInScythe
co8n720
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>In true PHP fashion, to parse ini strings in a non-retarded way you need to do this: parse_ini_string($str, false, INI_SCANNER_RAW);<|eor|><|soopr|>That's what I ended up doing. It's funny how whatever you think the sane default for a PHP setting is, it's the exact opposite - one can almost use it as a rule of thumb. Much like how PDO per default swallows errors and you have to configure it to throw exceptions.<|eoopr|><|sor|>PHP target development is quick and accessible. If you know enough about programming to be an expert then you can configure expert settings. Yes, that can lead to some esoteric issues which may not be thought out well, and yes there are still legacy issues which could fairly easily be mitigated by default namespaces, but, really, in the end, I'm glad PHP does exist at least for an agile project development or small organizations.<|eor|><|sor|>Esoteric, rare corner cases like Norwegians using your system.<|eor|><|eols|><|endoftext|>
11
lolphp
LeartS
co3peaf
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>Actually `"no"==false` and `"yes"==true, but "" and "1" is what you get if you convert them to strings. php -r "var_dump(false.'');" string(0) "" php -r "var_dump(true.'');" string(1) "1" php -r "var_dump(true=='1');" bool(true) php -r "var_dump(false=='');" bool(true) <|eor|><|sor|> > Actually "no"==false and `"yes"==true For real? <|eor|><|eols|><|endoftext|>
9
lolphp
andsens
co3zc4k
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>Wait, how do you do if you're norwegian?<|eor|><|sor|>There's no such thing as Norway or Norwegian language. It's all part of the Glorious Kingdom of Denmark. Source: Rasmus Lerdorf is Danish.<|eor|><|soopr|>Yeah. We're not too proud of that though.... On the other hand we have Bjarne Stroustrup (C++), Poul-Henning Kamp (FreeBSD), David Heinemeier Hansson (RoR) and Lars Bak (V8)<|eoopr|><|eols|><|endoftext|>
9
lolphp
Martin8412
co414sc
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>Wait, how do you do if you're norwegian?<|eor|><|sor|>There's no such thing as Norway or Norwegian language. It's all part of the Glorious Kingdom of Denmark. Source: Rasmus Lerdorf is Danish.<|eor|><|soopr|>Yeah. We're not too proud of that though.... On the other hand we have Bjarne Stroustrup (C++), Poul-Henning Kamp (FreeBSD), David Heinemeier Hansson (RoR) and Lars Bak (V8)<|eoopr|><|sor|>Don't forget Anders Hejlsberg(C#, Delphi, Turbo Pascal)<|eor|><|eols|><|endoftext|>
9
lolphp
vytah
co3z0qf
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>Wait, how do you do if you're norwegian?<|eor|><|sor|>There's no such thing as Norway or Norwegian language. It's all part of the Glorious Kingdom of Denmark. Source: Rasmus Lerdorf is Danish.<|eor|><|eols|><|endoftext|>
8
lolphp
LeartS
co3q66b
<|sols|><|sot|>'no' == ''; 'yes' == '1'<|eot|><|sol|>http://3v4l.org/8ILmg<|eol|><|sor|>Actually `"no"==false` and `"yes"==true, but "" and "1" is what you get if you convert them to strings. php -r "var_dump(false.'');" string(0) "" php -r "var_dump(true.'');" string(1) "1" php -r "var_dump(true=='1');" bool(true) php -r "var_dump(false=='');" bool(true) <|eor|><|sor|> > Actually "no"==false and `"yes"==true For real? <|eor|><|sor|>When it's an INI setting, yes.<|eor|><|sor|>Oh ok, I thought that was valid generally, which would've been insane. my fault for not reading the linked post. <|eor|><|eols|><|endoftext|>
5
lolphp
aleczapka
2e3dxy
<|sols|><|sot|>What's the most cursed programming language?<|eot|><|sol|>https://github.com/Dobiasd/programming-language-subreddits-and-their-choice-of-words/blob/master/README.md#cursing<|eol|><|eols|><|endoftext|>
57
lolphp
mrwhistler
cjvq4bq
<|sols|><|sot|>What's the most cursed programming language?<|eot|><|sol|>https://github.com/Dobiasd/programming-language-subreddits-and-their-choice-of-words/blob/master/README.md#cursing<|eol|><|sor|>Shit.<|eor|><|eols|><|endoftext|>
11
lolphp
Aerokaiser
cjvt4wl
<|sols|><|sot|>What's the most cursed programming language?<|eot|><|sol|>https://github.com/Dobiasd/programming-language-subreddits-and-their-choice-of-words/blob/master/README.md#cursing<|eol|><|sor|>Shit.<|eor|><|sor|>Crap.<|eor|><|sor|>Hate.<|eor|><|eols|><|endoftext|>
8
lolphp
polish_niceguy
cjvrybv
<|sols|><|sot|>What's the most cursed programming language?<|eot|><|sol|>https://github.com/Dobiasd/programming-language-subreddits-and-their-choice-of-words/blob/master/README.md#cursing<|eol|><|sor|>Shit.<|eor|><|sor|>Crap.<|eor|><|eols|><|endoftext|>
5
lolphp
Takeoded
ef8ob0
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|eols|><|endoftext|>
59
lolphp
Altreus
fc04qhx
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|soopr|>the crc32() function use an algorithm called "crc32b", and hash("crc32",$d) apparently use "the ITU I.363.5 algorithm" (whatever that is), and if you want crc32b from hash(), use hash("crc32b",...) instead.. (got that from the comments at [https://www.php.net/manual/en/function.hash-algos.php](https://www.php.net/manual/en/function.hash-algos.php) and this SO post: [https://stackoverflow.com/a/15861105/1067003](https://stackoverflow.com/a/15861105/1067003) )<|eoopr|><|sor|>And the place where CRC32 is (was) most widely is is PERL. The \`crc32()\` is not compatible with the PERL implementation. That was a mess that I'd seen half a dozen times, though the last time was at least a decade ago. Thankfully, I haven't seen PERL in a decade!<|eor|><|sor|>Perl developer here It's Perl not PERL Merry Christmas<|eor|><|eols|><|endoftext|>
20
lolphp
Takeoded
fbyyho2
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|soopr|>the crc32() function use an algorithm called "crc32b", and hash("crc32",$d) apparently use "the ITU I.363.5 algorithm" (whatever that is), and if you want crc32b from hash(), use hash("crc32b",...) instead.. (got that from the comments at [https://www.php.net/manual/en/function.hash-algos.php](https://www.php.net/manual/en/function.hash-algos.php) and this SO post: [https://stackoverflow.com/a/15861105/1067003](https://stackoverflow.com/a/15861105/1067003) )<|eoopr|><|eols|><|endoftext|>
19
lolphp
Takeoded
fbyykws
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|sor|>You use the wrong algorithm. You want "crc32b" when using the hash function: $str="Wello!"; $h1=dechex(crc32($str)); $h2=hash("crc32b",$str); var_dump($h1===$h2,$h1,$h2); bool(true) string(8) "6faa7c18" string(8) "6faa7c18"<|eor|><|soopr|>yeah, so why is the function called crc32() and not crc32b() ?<|eoopr|><|eols|><|endoftext|>
19
lolphp
AyrA_ch
fbyyiqx
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|sor|>You use the wrong algorithm. You want "crc32b" when using the hash function: $str="Wello!"; $h1=dechex(crc32($str)); $h2=hash("crc32b",$str); var_dump($h1===$h2,$h1,$h2); bool(true) string(8) "6faa7c18" string(8) "6faa7c18"<|eor|><|eols|><|endoftext|>
16
lolphp
AyrA_ch
fbyyxk0
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|sor|>You use the wrong algorithm. You want "crc32b" when using the hash function: $str="Wello!"; $h1=dechex(crc32($str)); $h2=hash("crc32b",$str); var_dump($h1===$h2,$h1,$h2); bool(true) string(8) "6faa7c18" string(8) "6faa7c18"<|eor|><|soopr|>yeah, so why is the function called crc32() and not crc32b() ?<|eoopr|><|sor|>because there are multiple algorithms that are called crc32.<|eor|><|soopr|>but how many algorithms are called "crc32b" ? (only system i know using crc32b is the BTRFS filesystem tho, but i'm sure there's others too)<|eoopr|><|sor|>No algorithm is called crc32b. PHP devs added the "b" because the algorithm has the same name but they needed to differentiate. It's still a crc32 variant. For more details, check this comment: https://www.php.net/manual/en/function.hash-file.php#104836<|eor|><|eols|><|endoftext|>
15
lolphp
AyrA_ch
fbyyu8w
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|sor|>You use the wrong algorithm. You want "crc32b" when using the hash function: $str="Wello!"; $h1=dechex(crc32($str)); $h2=hash("crc32b",$str); var_dump($h1===$h2,$h1,$h2); bool(true) string(8) "6faa7c18" string(8) "6faa7c18"<|eor|><|soopr|>yeah, so why is the function called crc32() and not crc32b() ?<|eoopr|><|sor|>because there are multiple algorithms that are called crc32.<|eor|><|eols|><|endoftext|>
14
lolphp
AyrA_ch
fbzx8nf
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|sor|>You use the wrong algorithm. You want "crc32b" when using the hash function: $str="Wello!"; $h1=dechex(crc32($str)); $h2=hash("crc32b",$str); var_dump($h1===$h2,$h1,$h2); bool(true) string(8) "6faa7c18" string(8) "6faa7c18"<|eor|><|soopr|>yeah, so why is the function called crc32() and not crc32b() ?<|eoopr|><|sor|>because there are multiple algorithms that are called crc32.<|eor|><|sor|>but if the crc32 function uses the crc32b algorithm, wouldn't it make more sense to call the function crc32b?<|eor|><|sor|>There is no such thing as crc32b. The "b" was added by the devs because names have to be unique.<|eor|><|eols|><|endoftext|>
11
lolphp
dotancohen
fc027ce
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|soopr|>the crc32() function use an algorithm called "crc32b", and hash("crc32",$d) apparently use "the ITU I.363.5 algorithm" (whatever that is), and if you want crc32b from hash(), use hash("crc32b",...) instead.. (got that from the comments at [https://www.php.net/manual/en/function.hash-algos.php](https://www.php.net/manual/en/function.hash-algos.php) and this SO post: [https://stackoverflow.com/a/15861105/1067003](https://stackoverflow.com/a/15861105/1067003) )<|eoopr|><|sor|>And the place where CRC32 is (was) most widely is is PERL. The \`crc32()\` is not compatible with the PERL implementation. That was a mess that I'd seen half a dozen times, though the last time was at least a decade ago. Thankfully, I haven't seen PERL in a decade!<|eor|><|eols|><|endoftext|>
9
lolphp
Miserable_Fuck
fc0t6k0
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|sor|>You use the wrong algorithm. You want "crc32b" when using the hash function: $str="Wello!"; $h1=dechex(crc32($str)); $h2=hash("crc32b",$str); var_dump($h1===$h2,$h1,$h2); bool(true) string(8) "6faa7c18" string(8) "6faa7c18"<|eor|><|soopr|>yeah, so why is the function called crc32() and not crc32b() ?<|eoopr|><|sor|>because there are multiple algorithms that are called crc32.<|eor|><|sor|>but if the crc32 function uses the crc32b algorithm, wouldn't it make more sense to call the function crc32b?<|eor|><|sor|>There is no such thing as crc32b. The "b" was added by the devs because names have to be unique.<|eor|><|sor|>So couldn't they add the b to the crc32 function name too? I'm still trying to figure out the reason why having crc32($str) and hash("crc32", $str) return two different results is acceptable. IMO keeping these misleading names for the sake of being technically correct is a lolphp in itself. If the name is the problem then couldn't they just make sure to use the same algorithm underneath?<|eor|><|eols|><|endoftext|>
8
lolphp
dotancohen
fc0c0md
<|sols|><|sot|>crc32($str) and hash("crc32",$str) use different algorithms (with different results)<|eot|><|sol|>https://3v4l.org/Ng7hi<|eol|><|soopr|>the crc32() function use an algorithm called "crc32b", and hash("crc32",$d) apparently use "the ITU I.363.5 algorithm" (whatever that is), and if you want crc32b from hash(), use hash("crc32b",...) instead.. (got that from the comments at [https://www.php.net/manual/en/function.hash-algos.php](https://www.php.net/manual/en/function.hash-algos.php) and this SO post: [https://stackoverflow.com/a/15861105/1067003](https://stackoverflow.com/a/15861105/1067003) )<|eoopr|><|sor|>And the place where CRC32 is (was) most widely is is PERL. The \`crc32()\` is not compatible with the PERL implementation. That was a mess that I'd seen half a dozen times, though the last time was at least a decade ago. Thankfully, I haven't seen PERL in a decade!<|eor|><|sor|>Perl developer here It's Perl not PERL Merry Christmas<|eor|><|sor|>Thanks. I'm always corrected on this, yet I still use the upper case. I guess I just do it to drive you guys nuts!<|eor|><|sor|>That's ok - I *could* have got bitchy about people hating on Perl but, well... It crimmus. Mer crimmus! <|eor|><|sor|>It's Hanukah too! ** !**<|eor|><|eols|><|endoftext|>
5
lolphp
vytah
yxk0x
<|sols|><|sot|>$date->modify('+0 days') adds one hour <|eot|><|sol|>https://bugs.php.net/bug.php?id=62896<|eol|><|eols|><|endoftext|>
58
lolphp
cwmonkey
c5zsdz7
<|sols|><|sot|>$date->modify('+0 days') adds one hour <|eot|><|sol|>https://bugs.php.net/bug.php?id=62896<|eol|><|sor|>Can't wait to hear the reason this isn't a bug!<|eor|><|eols|><|endoftext|>
20
lolphp
Andryu67
c5zrema
<|sols|><|sot|>$date->modify('+0 days') adds one hour <|eot|><|sol|>https://bugs.php.net/bug.php?id=62896<|eol|><|sor|>Finally, a /r/lolphp post that legitimately scares me.<|eor|><|eols|><|endoftext|>
15
lolphp
Liorithiel
c5zvvl1
<|sols|><|sot|>$date->modify('+0 days') adds one hour <|eot|><|sol|>https://bugs.php.net/bug.php?id=62896<|eol|><|sor|>I bet someone will answer it is not a bug, because calling `modify` with `0` as parameter doesn't make sense.<|eor|><|eols|><|endoftext|>
14
lolphp
vytah
c5zyqlr
<|sols|><|sot|>$date->modify('+0 days') adds one hour <|eot|><|sol|>https://bugs.php.net/bug.php?id=62896<|eol|><|sor|>I bet someone will answer it is not a bug, because calling `modify` with `0` as parameter doesn't make sense.<|eor|><|soopr|>What do you say about this then? $date = new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST')); echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n"; $date->modify('+1 day'); echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n"; 2012-08-21 22:00:00 GMT+0000 (offset 0) 2012-08-22 23:00:00 GMT+0000 (offset 0) Da fuck is going on in PHP devs' heads?<|eoopr|><|eols|><|endoftext|>
12
lolphp
infinull
c5ztch5
<|sols|><|sot|>$date->modify('+0 days') adds one hour <|eot|><|sol|>https://bugs.php.net/bug.php?id=62896<|eol|><|sor|>As far as I am concerned PHP is a hilarious spectator sport.<|eor|><|sor|>Hey man some of us have to maintain code written in PHP... that we wrote as Freshman. And by we, I mean me. Me 4yrs ago was pretty clever, but he was not wise.<|eor|><|eols|><|endoftext|>
10
lolphp
sumdog
c5zufol
<|sols|><|sot|>$date->modify('+0 days') adds one hour <|eot|><|sol|>https://bugs.php.net/bug.php?id=62896<|eol|><|sor|>As far as I am concerned PHP is a hilarious spectator sport.<|eor|><|sor|>Hey man some of us have to maintain code written in PHP... that we wrote as Freshman. And by we, I mean me. Me 4yrs ago was pretty clever, but he was not wise.<|eor|><|sor|>I'm currently working a contract job where we are moving a cold fusion app to PHP...&#3232;\_&#3232;<|eor|><|eols|><|endoftext|>
9
lolphp
infinull
c5ztd61
<|sols|><|sot|>$date->modify('+0 days') adds one hour <|eot|><|sol|>https://bugs.php.net/bug.php?id=62896<|eol|><|sor|>Can't wait to hear the reason this isn't a bug!<|eor|><|sor|>Probably something about timezones (see the full example, datetime with timezone doesn't have the problem)<|eor|><|eols|><|endoftext|>
6
lolphp
esquilax
c5zwvp2
<|sols|><|sot|>$date->modify('+0 days') adds one hour <|eot|><|sol|>https://bugs.php.net/bug.php?id=62896<|eol|><|sor|>I bet someone will answer it is not a bug, because calling `modify` with `0` as parameter doesn't make sense.<|eor|><|sor|>It does, for sufficiently large values of 0.<|eor|><|eols|><|endoftext|>
6
lolphp
vytah
c5zotn3
<|sols|><|sot|>$date->modify('+0 days') adds one hour <|eot|><|sol|>https://bugs.php.net/bug.php?id=62896<|eol|><|soopr|>I've reproduced the bug for following dates: $date = new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST')); echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n"; $date->modify('+0 days'); echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n"; $date = new DateTime('@'.strtotime('2012-08-22 12:00:00 CEST')); /* echo and modify as above */ $date = new DateTime('@'.strtotime('2012-02-02 02:02:02 CEST')); /* echo and modify as above */ Results: 2012-08-21 22:00:00 GMT+0000 (offset 0) 2012-08-21 23:00:00 GMT+0000 (offset 0) 2012-08-22 10:00:00 GMT+0000 (offset 0) 2012-08-22 11:00:00 GMT+0000 (offset 0) 2012-02-02 00:02:02 GMT+0000 (offset 0) 2012-02-02 01:02:02 GMT+0000 (offset 0) I have no idea what's going on there. <|eoopr|><|eols|><|endoftext|>
5
lolphp
ealf
kso6p
<|sols|><|sot|>If error reporting is on, htmlspecialchars() will ignore invalid strings silently. If error reporting is *off*, it will throw an error. This is not a bug, it's an intentional security feature.<|eot|><|sol|>https://bugs.php.net/bug.php?id=47494<|eol|><|eols|><|endoftext|>
61
lolphp
ealf
c2o4odz
<|sols|><|sot|>If error reporting is on, htmlspecialchars() will ignore invalid strings silently. If error reporting is *off*, it will throw an error. This is not a bug, it's an intentional security feature.<|eot|><|sol|>https://bugs.php.net/bug.php?id=47494<|eol|><|sor|>I'm confused. This is supposed to be a security feature? Blowing up in production, but silently failing during debugging is supposed to be a *good* thing? Who the fuck thought this was a good idea?<|eor|><|soopr|>> Who the fuck thought this was a good idea? [2011-05-03 17:33 UTC] [**rasmus**](http://en.wikipedia.org/wiki/Rasmus_Lerdorf)@php.net "This isn't a logic error. The idea is to prevent a user-triggered information leak by not showing this error to the user in case a production server is misconfigured and running with display_errors turned on."<|eoopr|><|eols|><|endoftext|>
11
lolphp
Tamber-Krain
c37gcqd
<|sols|><|sot|>If error reporting is on, htmlspecialchars() will ignore invalid strings silently. If error reporting is *off*, it will throw an error. This is not a bug, it's an intentional security feature.<|eot|><|sol|>https://bugs.php.net/bug.php?id=47494<|eol|><|sor|>I'm confused. This is supposed to be a security feature? Blowing up in production, but silently failing during debugging is supposed to be a *good* thing? Who the fuck thought this was a good idea?<|eor|><|soopr|>> Who the fuck thought this was a good idea? [2011-05-03 17:33 UTC] [**rasmus**](http://en.wikipedia.org/wiki/Rasmus_Lerdorf)@php.net "This isn't a logic error. The idea is to prevent a user-triggered information leak by not showing this error to the user in case a production server is misconfigured and running with display_errors turned on."<|eoopr|><|sor|>If that's such a problem, why don't they make everything fail silently when display_errors is on?<|eor|><|sor|>You expect them to be *consistently* incompetent?<|eor|><|eols|><|endoftext|>
10
lolphp
pinkgothic
c2njo9f
<|sols|><|sot|>If error reporting is on, htmlspecialchars() will ignore invalid strings silently. If error reporting is *off*, it will throw an error. This is not a bug, it's an intentional security feature.<|eot|><|sol|>https://bugs.php.net/bug.php?id=47494<|eol|><|sor|>It's like they never learnt from their `magic_quotes` debacle. :(<|eor|><|eols|><|endoftext|>
8
lolphp
quchen
119wum2
<|sols|><|sot|>Password_verify() always returns true with some hash<|eot|><|sol|>https://bugs.php.net/bug.php?id=81744<|eol|><|eols|><|endoftext|>
58