subreddit
stringclasses
7 values
author
stringlengths
3
20
id
stringlengths
5
7
content
stringlengths
67
30.4k
score
int64
0
140k
lolphp
ZorbaTHut
fk7qbcb
<|sols|><|sot|>Array is higher than infinity<|eot|><|sol|>https://3v4l.org/iONLA<|eol|><|sor|>Then you don't have implicit conversions. Not to mention there is no function call in a simple comparison Then you just get errors when you try to implicitly convert, which is a feature of PHP 7 anyway, is it not?<|eor|><|sor|>Implicit conversions make *some* sense when you have an implicit conversion that makes sense. You're moving into nutcase territory when you just decide to do arbitrary things so that everything can convert to everything else. In this case, it doesn't make sense to compare two tables, and there's no sensible conversion for either table where it makes sense to compare to the other table. It should just spit out an error. If the language designer doesn't want to make it an exception or a terminating error, it should *at least* follow the pattern established by NaN and return false.<|eor|><|sor|> >If the language designer doesn't want to make it an exception or a terminating error, it should *at least* follow the pattern established by NaN and return false. Is this not what the language designer has done? What's wrong with returning true? It's a defined case so it's not like you can blame the language if you were expecting an array to be less than Infinity, let alone if you're relying on such a comparison then there's much bigger problems in the code being written. If you rely on implicit conversions in places where edge cases may screw you, like the string 0 being an integer 0 which can evaluate to false, then I think you're using the language wrong. The implementation of the implicit conversion engine is quite elegant in that everything can convert to everything, I think that's pretty cool, and I recognize the limitations of such a design.<|eor|><|sor|>> Is this not what the language designer has done? What's wrong with returning true? It doesn't follow established precedent, which is "return false if things aren't comparable".<|eor|><|sor|>But one could argue you can compare nan with itself, which seems completely logical, yet doing that returns false. It's not about things being incomparable returning false, nan has to be detectable so they make any comparison with nan return false, allowing you to detect nan by comparing the variable to itself. There's no need to define this situation as returning false, and if you did, 0 would be greater than an array. Making all comparisons to arrays return false would work, but what situation are you solving by doing that? Anybody comparing to arrays has other problems, which are solved via typehinting and forcing type safety.<|eor|><|sor|>> But one could argue you can compare nan with itself, yet doing that returns false. Yes. It's nasty, but at least it's consistent with nan. > It's not about things being incomparable returning false, nan has to be detectable so they make any comparison with nan return false, allowing you to detect nan by comparing the variable to itself. This is bad logic - it's easy to detect nan by just checking the bit pattern of the underlying float. The reason comparing nan with itself returns false is that the underlying CPU does that; it needs to do *something* and the only other vaguely-sensible option is a CPU exception, which nobody wants to deal with. > There's no need to define this situation as returning false It's better than returning true because it's consistent with existing behavior. "At least it's consistent" isn't a great justification, but it's better than nothing. > and if you did, 0 would be greater than an array. I don't see why - why would it be?<|eor|><|sor|>You're right I'm talking out of my ass, you can definitely just establish a nan constant to compare to floats to detect nan. And yeah I don't disagree returning false on nonsense comparisons really does seem like a decent improvement. I imagine there are edge cases with that solution too though, but probably not as bad, and like you say, at least it's consistent.<|eor|><|sor|>> You're right I'm talking out of my ass, you can definitely just establish a nan constant to compare to floats to detect nan. Entertainingly, this actually isn't possible - NaN occupies a *surprisingly* large swath of the possible float bit patterns. There's almost 2^24 valid 32-bit NaN values, and [a rather astonishing 2^51 valid 64-bit NaN values](https://anniecherkaev.com/the-secret-life-of-nan). I, and many others, have used this to embed extra information in floating-point values; you can actually use it for a variant type which can store an entire 32-bit pointer in specially-crafted NaNs, and in fact Javascript implementations usually do this. But it's a few simple bit operations to figure out if something is a NaN. > I imagine there are edge cases with that solution too though, but probably not as bad, and like you say, at least it's consistent. Yeah, it is occasionally really awkward. My favorite gotcha moment is that some sort algorithms break if the elements don't obey total ordering, and NaN doesn't obey total ordering :(<|eor|><|eols|><|endoftext|>
5
lolphp
Takeoded
75sq2z
<|sols|><|sot|>if there's no connection, the programmer probably wants an empty string.<|eot|><|sol|>http://php.net/manual/en/mysqli.real-escape-string.php#58650<|eol|><|eols|><|endoftext|>
44
lolphp
katafrakt
do9csx6
<|sols|><|sot|>if there's no connection, the programmer probably wants an empty string.<|eot|><|sol|>http://php.net/manual/en/mysqli.real-escape-string.php#58650<|eol|><|soopr|>well, its 11 years since that was posted, but at least in 7.0.22 with Xdebug, things looks better (its a NULL instead of a string, and a warning) - still would prefer an exception though. > php -r '$conn=NULL;var_dump(mysqli_real_escape_string($conn,"foo"));' > PHP Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in > Command line code on line 1 > PHP Stack trace: > PHP 1. {main}() Command line code:0 > PHP 2. mysqli_real_escape_string() Command line code:1 > Command line code:1: > NULL <|eoopr|><|sor|>I wonder how many codebases rely on this empty string and are therefore unable to upgrade to PHP7.<|eor|><|eols|><|endoftext|>
20
lolphp
Takeoded
do8n006
<|sols|><|sot|>if there's no connection, the programmer probably wants an empty string.<|eot|><|sol|>http://php.net/manual/en/mysqli.real-escape-string.php#58650<|eol|><|soopr|>well, its 11 years since that was posted, but at least in 7.0.22 with Xdebug, things looks better (its a NULL instead of a string, and a warning) - still would prefer an exception though. > php -r '$conn=NULL;var_dump(mysqli_real_escape_string($conn,"foo"));' > PHP Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in > Command line code on line 1 > PHP Stack trace: > PHP 1. {main}() Command line code:0 > PHP 2. mysqli_real_escape_string() Command line code:1 > Command line code:1: > NULL <|eoopr|><|eols|><|endoftext|>
15
lolphp
ithcy
do9slxj
<|sols|><|sot|>if there's no connection, the programmer probably wants an empty string.<|eot|><|sol|>http://php.net/manual/en/mysqli.real-escape-string.php#58650<|eol|><|soopr|>well, its 11 years since that was posted, but at least in 7.0.22 with Xdebug, things looks better (its a NULL instead of a string, and a warning) - still would prefer an exception though. > php -r '$conn=NULL;var_dump(mysqli_real_escape_string($conn,"foo"));' > PHP Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in > Command line code on line 1 > PHP Stack trace: > PHP 1. {main}() Command line code:0 > PHP 2. mysqli_real_escape_string() Command line code:1 > Command line code:1: > NULL <|eoopr|><|sor|>Well its your own fault for not using PDO! I mean prepared statements! I mean... wait whats the secure way to do SQL in php?<|eor|><|eols|><|endoftext|>
10
lolphp
nikic
doa972j
<|sols|><|sot|>if there's no connection, the programmer probably wants an empty string.<|eot|><|sol|>http://php.net/manual/en/mysqli.real-escape-string.php#58650<|eol|><|soopr|>well, its 11 years since that was posted, but at least in 7.0.22 with Xdebug, things looks better (its a NULL instead of a string, and a warning) - still would prefer an exception though. > php -r '$conn=NULL;var_dump(mysqli_real_escape_string($conn,"foo"));' > PHP Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in > Command line code on line 1 > PHP Stack trace: > PHP 1. {main}() Command line code:0 > PHP 2. mysqli_real_escape_string() Command line code:1 > Command line code:1: > NULL <|eoopr|><|sor|>It most likely always behaved that way. Suppressing warnings and treating the result as a string (null casts to the empty string), presumably.<|eor|><|eols|><|endoftext|>
5
lolphp
the_real_natenator
5v3dt1
<|soss|><|sot|>parse_url and parse_str<|eot|><|sost|>Two functions, both in the same function group, return completely differently: void parse_str($query_string, &$return) array parse_url($url) Consistency, lol. tldr: one returns via reference variable, and the other returns properly EDIT 1: Formatting<|eost|><|eoss|><|endoftext|>
45
lolphp
pilif
ddz0jjj
<|soss|><|sot|>parse_url and parse_str<|eot|><|sost|>Two functions, both in the same function group, return completely differently: void parse_str($query_string, &$return) array parse_url($url) Consistency, lol. tldr: one returns via reference variable, and the other returns properly EDIT 1: Formatting<|eost|><|sor|>This is because `parse_str` is even worse: when not given a reference, it will create and/or overwrite(!) local variables<|eor|><|eoss|><|endoftext|>
25
lolphp
the_alias_of_andrea
ddz3x83
<|soss|><|sot|>parse_url and parse_str<|eot|><|sost|>Two functions, both in the same function group, return completely differently: void parse_str($query_string, &$return) array parse_url($url) Consistency, lol. tldr: one returns via reference variable, and the other returns properly EDIT 1: Formatting<|eost|><|sor|>I'm surprised one is not called not called str_parse... you know "str_replace" for example? This is why it's such a headache to remember php function names.<|eor|><|sor|>It's not even really a *string* function, it should really be `query_parse` or even `parse_query`. PHP is such a mess.<|eor|><|eoss|><|endoftext|>
13
lolphp
the_alias_of_andrea
de0zyea
<|soss|><|sot|>parse_url and parse_str<|eot|><|sost|>Two functions, both in the same function group, return completely differently: void parse_str($query_string, &$return) array parse_url($url) Consistency, lol. tldr: one returns via reference variable, and the other returns properly EDIT 1: Formatting<|eost|><|sor|>I'm surprised one is not called not called str_parse... you know "str_replace" for example? This is why it's such a headache to remember php function names.<|eor|><|sor|>It's not even really a *string* function, it should really be `query_parse` or even `parse_query`. PHP is such a mess.<|eor|><|soopr|>I agree, I think it should be named better.<|eoopr|><|sor|>Is there a shim for PHP that makes all the functions and tools behave in a consistent manner?<|eor|><|sor|>http://python.org/ ?<|eor|><|eoss|><|endoftext|>
10
lolphp
the_alias_of_andrea
ddz3wod
<|soss|><|sot|>parse_url and parse_str<|eot|><|sost|>Two functions, both in the same function group, return completely differently: void parse_str($query_string, &$return) array parse_url($url) Consistency, lol. tldr: one returns via reference variable, and the other returns properly EDIT 1: Formatting<|eost|><|sor|>This is because `parse_str` is even worse: when not given a reference, it will create and/or overwrite(!) local variables<|eor|><|sor|>Thankfully, [this will be deprecated soon](https://wiki.php.net/rfc/deprecations_php_7_2#parse_str_without_second_argument).<|eor|><|eoss|><|endoftext|>
9
lolphp
cfreak2399
ddzd2hi
<|soss|><|sot|>parse_url and parse_str<|eot|><|sost|>Two functions, both in the same function group, return completely differently: void parse_str($query_string, &$return) array parse_url($url) Consistency, lol. tldr: one returns via reference variable, and the other returns properly EDIT 1: Formatting<|eost|><|sor|>I'm surprised one is not called not called str_parse... you know "str_replace" for example? This is why it's such a headache to remember php function names.<|eor|><|soopr|>Well, it's not really a *string* function per se. The "string" refers to "query string" that its parsing into variables. I do agree that it should be something more like `parse_query`. If you made it `str_parse`, that could get confusing because then it's mistaken as being a part of the `str` function group. EDIT 1&2: Formatting<|eoopr|><|sor|>Then we'll wonder if `parse_query` refers to a url query string or a SQL library. Perhaps `real_parse_url_query_string_we_mean_it_this_time()`<|eor|><|eoss|><|endoftext|>
7
lolphp
the_real_natenator
ddza411
<|soss|><|sot|>parse_url and parse_str<|eot|><|sost|>Two functions, both in the same function group, return completely differently: void parse_str($query_string, &$return) array parse_url($url) Consistency, lol. tldr: one returns via reference variable, and the other returns properly EDIT 1: Formatting<|eost|><|sor|>This is because `parse_str` is even worse: when not given a reference, it will create and/or overwrite(!) local variables<|eor|><|soopr|>That is disgusting. I didn't know that; I thought it would error without the second parameter.<|eoopr|><|eoss|><|endoftext|>
6
lolphp
barubary
de2l1q0
<|soss|><|sot|>parse_url and parse_str<|eot|><|sost|>Two functions, both in the same function group, return completely differently: void parse_str($query_string, &$return) array parse_url($url) Consistency, lol. tldr: one returns via reference variable, and the other returns properly EDIT 1: Formatting<|eost|><|sor|>I'm surprised one is not called not called str_parse... you know "str_replace" for example? This is why it's such a headache to remember php function names.<|eor|><|soopr|>Well, it's not really a *string* function per se. The "string" refers to "query string" that its parsing into variables. I do agree that it should be something more like `parse_query`. If you made it `str_parse`, that could get confusing because then it's mistaken as being a part of the `str` function group. EDIT 1&2: Formatting<|eoopr|><|sor|>Then we'll wonder if `parse_query` refers to a url query string or a SQL library. Perhaps `real_parse_url_query_string_we_mean_it_this_time()`<|eor|><|soopr|>While I do understand that back in the old days, they wanted to keep function names short for faster development, `parse_str`. Really? Lol. My coworkers mock me for my verbose naming conventions, yet, they've almost never asked me what my functions and variables mean. And now that we're out of the dark ages without IDEs, auto-completion is a thing now.<|eoopr|><|sor|>It isn't a problem of verbosity. It's a problem of having to distinguish between multiple functions that do the same thing in slightly different ways,. No other language throws everything plus the kitchen sink into the global namespace. No other language feels the need to leave bugged functions in and create a separate one with a different name because someone's implementation relies on the old behavior. Sane namespace conventions would go a long way toward fixing PHP (and no I don't mean the terrible excuse for namespaces they already implemented) That said, not everyone uses an IDE. I hate them because looking up the function names or trying to provide me with a useless piece of documentation on something like for loops is slow as hell.<|eor|><|sor|>> No other language throws everything plus the kitchen sink into the global namespace. C does. But C was invented when linkers would reject function names longer than 8 characters. > they wanted to keep function names short for faster development, parse_str ~~for faster development~~ [for better hashing](http://news.php.net/php.internals/70691) /s <|eor|><|sor|>> But C was invented when linkers would reject function names longer than 8 characters. It's slightly worse: C89 is fine with an implementation that cuts off external identifiers after 6 characters and uppercases them. That is, if you want to be truly 100% portable, you have to make sure that your (non-`static`) function names are [unique in the first 6 characters, case insensitively](http://c-faq.com/ansi/extidsignif.html). This is why we have functions such as `strlen`, `strcat`, `strcpy`, etc. > [for better hashing](http://news.php.net/php.internals/70691) Which is so stupid it's sad. The code contains a hardcoded hash table (`cmd_table`, really just an array of structs), which is indexed by `strlen(fnc_name)`, thus "forcing" the language designer to choose names of well-distributed length for performance reasons. Except PHP only had 97 builtins at that point, so even linear search would have been fast enough anyway. Or he could have used a sorted array and `bsearch` (a standard C function) to do a binary search, which would have needed only 7 comparisons in the worst case. Besides, if you have a hardcoded table anyway, why not use a hardcoded trie instead of a hash? The code would have looked like this: switch (fnc[0]) { case 'a': if (strcmp(fnc + 1, "bs") == 0) return cmd_table.abs; break; case 'b': switch (fnc[1]) { case 'i': if (strcmp(fnc + 2, "ndec") == 0) return cmd_table.bindec; break; case 'r': if (strcmp(fnc + 2, "eak") == 0) return cmd_table.break_; break; } break; case 'c': switch (fnc[1]) { case 'a': if (strcmp(fnc + 2, "se") == 0) return cmd_table.case_; break; case 'h': switch (fnc[2]) { case 'd': if (strcmp(fnc + 3, "ir") == 0) return cmd_table.chdir; break; case 'g': if (strcmp(fnc + 3, "rp") == 0) return cmd_table.chgrp; break; case 'm': if (strcmp(fnc + 3, "od") == 0) return cmd_table.chmod; break; case 'o': if (strcmp(fnc + 3, "wn") == 0) return cmd_table.chown; break; case 'r': if (strcmp(fnc + 3, "") == 0) return cmd_table.chr; break; } break; case 'l': if (strcmp(fnc + 2, "osedir") == 0) return cmd_table.closedir; break; case 'o': switch (fnc[2]) { case 's': if (strcmp(fnc + 3, "") == 0) return cmd_table.cos; break; case 'u': if (strcmp(fnc + 3, "nt") == 0) return cmd_table.count; break; } break; case 'r': if (strcmp(fnc + 2, "ypt") == 0) return cmd_table.crypt; break; } break; ... } return NULL; This is admittedly tedious and probably should be generated by some tool (the structure is very regular), but it's totally feasible to write by hand, and it scales with any number of reserved words. It has the additional advantage of not needing any fancy data structures or algorithms or dynamic memory allocation. (It's what I used when I wrote my first toy interpreters.)<|eor|><|eoss|><|endoftext|>
6
lolphp
polish_niceguy
ddznq35
<|soss|><|sot|>parse_url and parse_str<|eot|><|sost|>Two functions, both in the same function group, return completely differently: void parse_str($query_string, &$return) array parse_url($url) Consistency, lol. tldr: one returns via reference variable, and the other returns properly EDIT 1: Formatting<|eost|><|sor|>I'm surprised one is not called not called str_parse... you know "str_replace" for example? This is why it's such a headache to remember php function names.<|eor|><|sor|>It's not even really a *string* function, it should really be `query_parse` or even `parse_query`. PHP is such a mess.<|eor|><|sor|>More like `http_parse_query`, similar to `http_build_query`, which is a surprisingly well named function in this whole mess.<|eor|><|eoss|><|endoftext|>
5
lolphp
00Davo
3n7q20
<|sols|><|sot|>Trying to implement DateTimeInterface raises a fatal error<|eot|><|sol|>http://php.net/manual/en/class.datetimeinterface.php<|eol|><|eols|><|endoftext|>
40
lolphp
BufferUnderpants
cvlx8cp
<|sols|><|sot|>Trying to implement DateTimeInterface raises a fatal error<|eot|><|sol|>http://php.net/manual/en/class.datetimeinterface.php<|eol|><|sor|>> backwards compatibility<|eor|><|sor|>Is that the rationale? The page just says that it was formerly intended to raise an error, but it didn't.<|eor|><|sor|>It's a jab at the commonly cited reason for keeping around weird behaviour, while this one time a change was introduced to explicitly break old code, for some under-explained reason.<|eor|><|eols|><|endoftext|>
15
lolphp
BufferUnderpants
cvltt1c
<|sols|><|sot|>Trying to implement DateTimeInterface raises a fatal error<|eot|><|sol|>http://php.net/manual/en/class.datetimeinterface.php<|eol|><|sor|>> backwards compatibility<|eor|><|eols|><|endoftext|>
13
lolphp
yrro
cvluy1w
<|sols|><|sot|>Trying to implement DateTimeInterface raises a fatal error<|eot|><|sol|>http://php.net/manual/en/class.datetimeinterface.php<|eol|><|sor|>> backwards compatibility<|eor|><|sor|>Is that the rationale? The page just says that it was formerly intended to raise an error, but it didn't.<|eor|><|eols|><|endoftext|>
10
lolphp
myaut
cvm521v
<|sols|><|sot|>Trying to implement DateTimeInterface raises a fatal error<|eot|><|sol|>http://php.net/manual/en/class.datetimeinterface.php<|eol|><|sor|>> backwards compatibility<|eor|><|sor|>In this case it is probably laziness of PHP devs. They are still distinguish "userland" classes (one that defined in PHP code) and "internal" classes (which are provided by interpreter). I presume that mixing them will cause a lot of problems, so instead of fixing them they just forbid that. EDIT: Here are PHP bug for this problem: https://bugs.php.net/bug.php?id=67118 Bug is caused by that exceptions are forbidden in internal classes, they are returning NULL. <|eor|><|eols|><|endoftext|>
9
lolphp
expugnator3000
cvmvfu4
<|sols|><|sot|>Trying to implement DateTimeInterface raises a fatal error<|eot|><|sol|>http://php.net/manual/en/class.datetimeinterface.php<|eol|><|sor|>[deleted]<|eor|><|sor|>...and this should not happen?<|eor|><|sor|>[deleted]<|eor|><|sor|>If it's an error then it shouldn't be an interface in the first place, since interfaces can usually (always) be implemented. But yes: Raising an error is better than doing the wrong thing<|eor|><|eols|><|endoftext|>
7
lolphp
expugnator3000
cvmm0jb
<|sols|><|sot|>Trying to implement DateTimeInterface raises a fatal error<|eot|><|sol|>http://php.net/manual/en/class.datetimeinterface.php<|eol|><|sor|>[deleted]<|eor|><|sor|>...and this should not happen?<|eor|><|eols|><|endoftext|>
5
lolphp
McGlockenshire
2zf243
<|sols|><|sot|>The person responsible for creating accounts for RFC voters uses arbitrary criteria to accept or decline accounts, dislikes the RFC voting concept, and seems to think that transparency is bad<|eot|><|sol|>http://marc.info/?l=php-internals&m=142662967407771&w=4<|eol|><|eols|><|endoftext|>
42
lolphp
that_which_is_lain
cpirzww
<|sols|><|sot|>The person responsible for creating accounts for RFC voters uses arbitrary criteria to accept or decline accounts, dislikes the RFC voting concept, and seems to think that transparency is bad<|eot|><|sol|>http://marc.info/?l=php-internals&m=142662967407771&w=4<|eol|><|sor|>> Now. Please go on and become famous by blogging about conspiracy theories (I've got plenty if you are short of ideas!) or whatever tickles your fancy - but please don't be dragging this onto the list. Good lord, how does this guy fit his head through regular sized doors?<|eor|><|sor|>With the way PHP goes, probably with a running start powered by obliviousness.<|eor|><|eols|><|endoftext|>
25
lolphp
willfe42
cpimsei
<|sols|><|sot|>The person responsible for creating accounts for RFC voters uses arbitrary criteria to accept or decline accounts, dislikes the RFC voting concept, and seems to think that transparency is bad<|eot|><|sol|>http://marc.info/?l=php-internals&m=142662967407771&w=4<|eol|><|sor|>> Now. Please go on and become famous by blogging about conspiracy theories (I've got plenty if you are short of ideas!) or whatever tickles your fancy - but please don't be dragging this onto the list. Good lord, how does this guy fit his head through regular sized doors?<|eor|><|eols|><|endoftext|>
14
lolphp
iftpadfs
cpk9g1b
<|sols|><|sot|>The person responsible for creating accounts for RFC voters uses arbitrary criteria to accept or decline accounts, dislikes the RFC voting concept, and seems to think that transparency is bad<|eot|><|sol|>http://marc.info/?l=php-internals&m=142662967407771&w=4<|eol|><|sor|>[deleted]<|eor|><|sor|>Highly depends on the community IMO. Linux and OpenBSD are good because they are managed by assholes. Php is bad because it is managed by assholes. Haskell is good because it's not managed by assholes. Voting would effect every community different and it's hard to say how if one does not try it out. I'm still very conservative on this issue and don't think one should try a different system every year.<|eor|><|sor|>[deleted]<|eor|><|sor|>OK, only by one. By a lovely one.<|eor|><|eols|><|endoftext|>
14
lolphp
iftpadfs
cpk71od
<|sols|><|sot|>The person responsible for creating accounts for RFC voters uses arbitrary criteria to accept or decline accounts, dislikes the RFC voting concept, and seems to think that transparency is bad<|eot|><|sol|>http://marc.info/?l=php-internals&m=142662967407771&w=4<|eol|><|sor|>[deleted]<|eor|><|sor|>Highly depends on the community IMO. Linux and OpenBSD are good because they are managed by assholes. Php is bad because it is managed by assholes. Haskell is good because it's not managed by assholes. Voting would effect every community different and it's hard to say how if one does not try it out. I'm still very conservative on this issue and don't think one should try a different system every year.<|eor|><|eols|><|endoftext|>
13
lolphp
domstersch
cpimzg1
<|sols|><|sot|>The person responsible for creating accounts for RFC voters uses arbitrary criteria to accept or decline accounts, dislikes the RFC voting concept, and seems to think that transparency is bad<|eot|><|sol|>http://marc.info/?l=php-internals&m=142662967407771&w=4<|eol|><|sor|>He says he doesn't like the RFC voting, then posts a [link to an article](http://producingoss.com/en/consensus-democracy.html) that has a huge screed on how to use votes to end disagreements, and how important the question of *who gets to vote* is. Oh, and my goodness, how relevant this section is to the STH fuckiness: > Occasionally a developer will object to the form of the ballot itself. Sometimes his concern is legitimate, for example that an important choice was left off or not described accurately. But other times a developer may be merely trying to stave off the inevitable, perhaps knowing that the vote probably won't go his way.<|eor|><|eols|><|endoftext|>
11
lolphp
iftpadfs
cpk9mu5
<|sols|><|sot|>The person responsible for creating accounts for RFC voters uses arbitrary criteria to accept or decline accounts, dislikes the RFC voting concept, and seems to think that transparency is bad<|eot|><|sol|>http://marc.info/?l=php-internals&m=142662967407771&w=4<|eol|><|sor|>[deleted]<|eor|><|sor|>Highly depends on the community IMO. Linux and OpenBSD are good because they are managed by assholes. Php is bad because it is managed by assholes. Haskell is good because it's not managed by assholes. Voting would effect every community different and it's hard to say how if one does not try it out. I'm still very conservative on this issue and don't think one should try a different system every year.<|eor|><|sor|>[deleted]<|eor|><|sor|>OK, only by one. By a lovely one.<|eor|><|sor|>[deleted]<|eor|><|sor|>Well it seems opinions on people differ. Or the definition of asshole. Linux all in all is indeed dominated by very friendly people.<|eor|><|eols|><|endoftext|>
6
lolphp
TortoiseWrath
214noa
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|eols|><|endoftext|>
46
lolphp
MeLoN_DO
cg9m09s
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|> > This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. To be fair, this is a very simple `goto`, it greatly limits the dangers of using it and limits sufficiently its scope so it's not too damaging for the compiler/optimizer. I _guess_ it _could_ be useful in _some_ cases.<|eor|><|eols|><|endoftext|>
40
lolphp
Innominate8
cg9mobl
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|>goto is a useful construct when used sparingly. Unfortunately a whole generation now exists who were told as students to never use goto and now believe it is the worst thing you can ever do when programming. Of the additions PHP has received over the years, goto is one of the smaller more well thought out ones that fit with the languages original design. Compared to the boxes of crap they've been duct taping and hot gluing onto the side since then goto was supremely well designed feature. Of course while the documentation explains how to use goto, it doesn't contain a single example that shows a legitimate reason to use it.<|eor|><|eols|><|endoftext|>
27
lolphp
dehrmann
cg9mqup
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|>Go/Golang also has goto. Just because everyone says its bad, doesn't exactly mean it doesn't have its uses. Building a web server in Go for example, would benefit from gotos. <|eor|><|sor|>I'd *much* rather have Java's block break. What I'm doing is more (aside from it being an obscure feature) clear, and it's safer&mdash;as safe as any other break. boolean isValid = false; validator: { if (!setup0()) { break validator; } ... if (!setup1()) { break validator; } ... if (!setup2()) { break validator; } ... isValid = true; }<|eor|><|eols|><|endoftext|>
17
lolphp
barubary
cg9oq0m
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|> > This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. To be fair, this is a very simple `goto`, it greatly limits the dangers of using it and limits sufficiently its scope so it's not too damaging for the compiler/optimizer. I _guess_ it _could_ be useful in _some_ cases.<|eor|><|sor|>In C you cannot jump out of a function (or file) either, so I'm not sure how greatly limited this really is. Also, what optimizer?<|eor|><|eols|><|endoftext|>
15
lolphp
nikic
cg9p7em
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|> > This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. To be fair, this is a very simple `goto`, it greatly limits the dangers of using it and limits sufficiently its scope so it's not too damaging for the compiler/optimizer. I _guess_ it _could_ be useful in _some_ cases.<|eor|><|sor|>In C you cannot jump out of a function (or file) either, so I'm not sure how greatly limited this really is. Also, what optimizer?<|eor|><|sor|>C has `longjmp` in addition to `goto`, which allows you to jump past stack frame boundaries.<|eor|><|eols|><|endoftext|>
15
lolphp
barubary
cg9oo56
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|>Go/Golang also has goto. Just because everyone says its bad, doesn't exactly mean it doesn't have its uses. Building a web server in Go for example, would benefit from gotos. <|eor|><|sor|>I'd *much* rather have Java's block break. What I'm doing is more (aside from it being an obscure feature) clear, and it's safer&mdash;as safe as any other break. boolean isValid = false; validator: { if (!setup0()) { break validator; } ... if (!setup1()) { break validator; } ... if (!setup2()) { break validator; } ... isValid = true; }<|eor|><|sor|>More like Perl's block break. :-) I'm not sure which language invented this feature, but perl1 (released in 1987) already had it. Java 1 came out in 1996, almost a decade later. What's more vexing is that despite PHP borrowing heavily from Perl (and the first versions of PHP/FI being written in Perl), it still managed to screw up so many things that worked well in Perl: * The `?:` operator: PHP's has the wrong associativity. * Namespaces: perl4 definitely had them in 1991, PHP only added them in 5.3 (2009). * Labelled `break`/`continue`: PHP only has `break N`, which terminates the Nth surrounding loop, which is fragile if you ever change the structure of your code (adding/removing blocks), and it was only in 5.4 (2012) that `N` was required to be a constant (instead of a runtime expression). * perl1 had `goto` but thanks to the aforementioned labelled `break`/`continue` I've never had to use it in Perl. So of course instead of supporting `break LABEL` PHP decides to add `goto` in 5.3 (2009). * This didn't exist in perl4, but anonymous functions/"lambdas": perl5 had them in 1996, PHP only added them in 5.3 (2009) and their implementation still sucks. (Bonus: The PHP manual misdocuments them as "anonymous functions, also known as *closures*" - yeah, buddy, that's not what closure means.)<|eor|><|eols|><|endoftext|>
13
lolphp
dagbrown
cg9ovo6
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|>Go/Golang also has goto. Just because everyone says its bad, doesn't exactly mean it doesn't have its uses. Building a web server in Go for example, would benefit from gotos. <|eor|><|sor|>It's not *having* goto that we're laughing at, it's *not having* it for the first 14 years of the language's existence and then one day around 2009, deciding, hey, we ought to have a goto statement. <|eor|><|sor|>And Java 8 included lambdas in 2014...each language grows how its maintainers choose to.<|eor|><|sor|>Yes, but lambdas are an advancement. A goto is a retrograde step.<|eor|><|eols|><|endoftext|>
10
lolphp
aaron552
cg9pxnm
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|> > This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. To be fair, this is a very simple `goto`, it greatly limits the dangers of using it and limits sufficiently its scope so it's not too damaging for the compiler/optimizer. I _guess_ it _could_ be useful in _some_ cases.<|eor|><|sor|>In C you cannot jump out of a function (or file) either, so I'm not sure how greatly limited this really is. Also, what optimizer?<|eor|><|sor|>In C, goto is used to implement pseudo-exceptions and clean up resources when a function could have multiple exit points. goto is not bad in C.<|eor|><|eols|><|endoftext|>
9
lolphp
tommorris
cgagoa4
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|>The justification for it seems to be "it's needed for low-level programming". The thought of people doing low-level programming in PHP rather than writing a goddamn PHP extension in C is more horrifying than the existence of goto in PHP. Of course, when someone decides they want to write an operating system kernel in PHP, goto will come in handy, I guess...<|eor|><|eols|><|endoftext|>
8
lolphp
RecursionIsRecursion
cg9r7as
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|> > This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. To be fair, this is a very simple `goto`, it greatly limits the dangers of using it and limits sufficiently its scope so it's not too damaging for the compiler/optimizer. I _guess_ it _could_ be useful in _some_ cases.<|eor|><|sor|>I agree, this actually appears to be a reasonable implementation. I am not sure what the lol part of lolphp is supposed to be. Whether or not goto should be used aside, it's a language feature.<|eor|><|sor|>In my opinion designing a language is just as much about what should NOT be in the language as what should. Type systems for instance is just a way to disallow a whole bunch of programs(some of which actually might work). If you just start with C and duct tape every possible language feature you come across to it, you end with C++ which I think we can all agree is not ideal.<|eor|><|sor|>Agreed. But in addition, the timing of the duct tape is also part of the "lol" - the design decision to add a GOTO was in 5.3?! Even if it is restricted, even if it's slightly useful in some cases...if it takes you this long to implement a semi-useful-but-ripe-for-abuse feature...maybe don't implement it at all.<|eor|><|eols|><|endoftext|>
8
lolphp
jsanc623
cg9l6cx
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|>Go/Golang also has goto. Just because everyone says its bad, doesn't exactly mean it doesn't have its uses. Building a web server in Go for example, would benefit from gotos. <|eor|><|eols|><|endoftext|>
7
lolphp
Rhomboid
cg9lx9e
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|>Go/Golang also has goto. Just because everyone says its bad, doesn't exactly mean it doesn't have its uses. Building a web server in Go for example, would benefit from gotos. <|eor|><|sor|>It's not *having* goto that we're laughing at, it's *not having* it for the first 14 years of the language's existence and then one day around 2009, deciding, hey, we ought to have a goto statement. <|eor|><|eols|><|endoftext|>
7
lolphp
DoctorWaluigiTime
cg9pdjv
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|> > This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. To be fair, this is a very simple `goto`, it greatly limits the dangers of using it and limits sufficiently its scope so it's not too damaging for the compiler/optimizer. I _guess_ it _could_ be useful in _some_ cases.<|eor|><|sor|>I agree, this actually appears to be a reasonable implementation. I am not sure what the lol part of lolphp is supposed to be. Whether or not goto should be used aside, it's a language feature.<|eor|><|eols|><|endoftext|>
6
lolphp
MeLoN_DO
cg9srij
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|> > This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. To be fair, this is a very simple `goto`, it greatly limits the dangers of using it and limits sufficiently its scope so it's not too damaging for the compiler/optimizer. I _guess_ it _could_ be useful in _some_ cases.<|eor|><|sor|>In C you cannot jump out of a function (or file) either, so I'm not sure how greatly limited this really is. Also, what optimizer?<|eor|><|sor|>Can you jump in a loop in C ? Because that's major. Also, PHP already allowed this: outer: for ($i=0; $i < 1; $i++) { for ($j=0; $j < 1; $j++) { break outer; } } And some people ended up doing this (which is awful): do { if (condition) { break; } // long list of operations } while (false) So why not support goto ? I dont say you should use it, just that the feature is kinda logical. Also, optimizer: http://en.wikipedia.org/wiki/List_of_PHP_accelerators#Comparison_of_features<|eor|><|eols|><|endoftext|>
6
lolphp
MeLoN_DO
cg9st41
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|> > This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. To be fair, this is a very simple `goto`, it greatly limits the dangers of using it and limits sufficiently its scope so it's not too damaging for the compiler/optimizer. I _guess_ it _could_ be useful in _some_ cases.<|eor|><|sor|>I agree, this actually appears to be a reasonable implementation. I am not sure what the lol part of lolphp is supposed to be. Whether or not goto should be used aside, it's a language feature.<|eor|><|sor|>In my opinion designing a language is just as much about what should NOT be in the language as what should. Type systems for instance is just a way to disallow a whole bunch of programs(some of which actually might work). If you just start with C and duct tape every possible language feature you come across to it, you end with C++ which I think we can all agree is not ideal.<|eor|><|sor|>Agreed. But in addition, the timing of the duct tape is also part of the "lol" - the design decision to add a GOTO was in 5.3?! Even if it is restricted, even if it's slightly useful in some cases...if it takes you this long to implement a semi-useful-but-ripe-for-abuse feature...maybe don't implement it at all.<|eor|><|sor|>That's a very point.<|eor|><|eols|><|endoftext|>
6
lolphp
dehrmann
cg9ms37
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|>goto is a useful construct when used sparingly. Unfortunately a whole generation now exists who were told as students to never use goto and now believe it is the worst thing you can ever do when programming. Of the additions PHP has received over the years, goto is one of the smaller more well thought out ones that fit with the languages original design. Compared to the boxes of crap they've been duct taping and hot gluing onto the side since then goto was supremely well designed feature. Of course while the documentation explains how to use goto, it doesn't contain a single example that shows a legitimate reason to use it.<|eor|><|sor|>I have a [comment above](http://www.reddit.com/r/lolphp/comments/214noa/the_goto_operator_was_added_in_php_53/cg9mqup) about a better construct for what people use goto for.<|eor|><|eols|><|endoftext|>
5
lolphp
Pat55word
cg9wwmg
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|>goto is a useful construct when used sparingly. Unfortunately a whole generation now exists who were told as students to never use goto and now believe it is the worst thing you can ever do when programming. Of the additions PHP has received over the years, goto is one of the smaller more well thought out ones that fit with the languages original design. Compared to the boxes of crap they've been duct taping and hot gluing onto the side since then goto was supremely well designed feature. Of course while the documentation explains how to use goto, it doesn't contain a single example that shows a legitimate reason to use it.<|eor|><|sor|>implying PHP was designed...<|eor|><|eols|><|endoftext|>
5
lolphp
ismtrn
cg9pvje
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|> > This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. To be fair, this is a very simple `goto`, it greatly limits the dangers of using it and limits sufficiently its scope so it's not too damaging for the compiler/optimizer. I _guess_ it _could_ be useful in _some_ cases.<|eor|><|sor|>I agree, this actually appears to be a reasonable implementation. I am not sure what the lol part of lolphp is supposed to be. Whether or not goto should be used aside, it's a language feature.<|eor|><|sor|>In my opinion designing a language is just as much about what should NOT be in the language as what should. Type systems for instance is just a way to disallow a whole bunch of programs(some of which actually might work). If you just start with C and duct tape every possible language feature you come across to it, you end with C++ which I think we can all agree is not ideal.<|eor|><|eols|><|endoftext|>
5
lolphp
MeLoN_DO
cg9svkz
<|sols|><|sot|>The goto operator was ADDED in PHP 5.3<|eot|><|sol|>http://us3.php.net/goto<|eol|><|sor|>Go/Golang also has goto. Just because everyone says its bad, doesn't exactly mean it doesn't have its uses. Building a web server in Go for example, would benefit from gotos. <|eor|><|sor|>I'd *much* rather have Java's block break. What I'm doing is more (aside from it being an obscure feature) clear, and it's safer&mdash;as safe as any other break. boolean isValid = false; validator: { if (!setup0()) { break validator; } ... if (!setup1()) { break validator; } ... if (!setup2()) { break validator; } ... isValid = true; }<|eor|><|sor|>That looks messy, why not use a closure (or a dedicated function) ? $validate = function() { if (!setup0()) return false; ... if (!setup1()) return false; ... if (!setup2()) return false; ... return true; }; $isValid = $validate();<|eor|><|eols|><|endoftext|>
5
lolphp
ajmarks
1pz6gn
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|eols|><|endoftext|>
47
lolphp
ajmarks
cd7j74g
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|soopr|>A bit back somebody pointed out the stupidity that is $string++ in PHP. What's even more PHP (read: inconsistent) is that $string-- doesn't undo that; it's a NOP.<|eoopr|><|eols|><|endoftext|>
14
lolphp
polish_niceguy
cd7xy1z
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|soopr|>A bit back somebody pointed out the stupidity that is $string++ in PHP. What's even more PHP (read: inconsistent) is that $string-- doesn't undo that; it's a NOP.<|eoopr|><|sor|>I'm sure there's a bug about it which has been closed by the developers who also told you how stupid you are for not understanding why this makes perfect sense.<|eor|><|sor|>There isn't. [I checked.](https://bugs.php.net/search.php?search_for=string+decrement+operator&boolean=1&limit=30&order_by=&direction=DESC&cmd=display&status=All&bug_type=All&project=All&php_os=&phpver=&cve_id=&assign=&author_email=&bug_age=0&bug_updated=0)<|eor|><|sor|>Well, obviously "[increment should be enough](https://bugs.php.net/bug.php?id=1235&edit=3)" for "unique ideas" since 1999. This whole subreddit should be named "unique ideas".<|eor|><|eols|><|endoftext|>
14
lolphp
cwmonkey
cd7jcgt
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|soopr|>A bit back somebody pointed out the stupidity that is $string++ in PHP. What's even more PHP (read: inconsistent) is that $string-- doesn't undo that; it's a NOP.<|eoopr|><|sor|>I'm sure there's a bug about it which has been closed by the developers who also told you how stupid you are for not understanding why this makes perfect sense.<|eor|><|eols|><|endoftext|>
13
lolphp
ajmarks
cd7meqz
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|sor|>Why is $string++ stupid? Plenty of things use that system, for instance excel column names. **EDIT**: I didn't mean in PHP, I meant the general concept. There exists a kind of base-26 notation where the next string after Z is AA and the next string after AZ is AB and so on. String incrementing (for [A-Z] strings) in Perl follows this pattern, rather than erroring or doing nothing. It's not so terrible. PHP, as someone said, copied this feature but got it wrong. <|eor|><|soopr|>Among other things, because of PHP's typing. It results in monstrosities like this: https://eval.in/60685. It also means that $string+1 != $string++. Edit: Also, Excel is hardly an example of a reasonable programming system.<|eoopr|><|eols|><|endoftext|>
8
lolphp
Lokaltog
cd7ocmz
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|sor|>Why is $string++ stupid? Plenty of things use that system, for instance excel column names. **EDIT**: I didn't mean in PHP, I meant the general concept. There exists a kind of base-26 notation where the next string after Z is AA and the next string after AZ is AB and so on. String incrementing (for [A-Z] strings) in Perl follows this pattern, rather than erroring or doing nothing. It's not so terrible. PHP, as someone said, copied this feature but got it wrong. <|eor|><|sor|>Not sure if you're being sarcastic, but how about converting a numeric char code to a single character string, or accessing a character from a string array by incrementing the array index? Then at least you know what behavior to expect. Incrementing a string with ++ makes absolutely no sense so the behavior isn't obvious. It should raise an error instead of silently doing *something*.<|eor|><|eols|><|endoftext|>
7
lolphp
ajmarks
cd7lrtq
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|soopr|>A bit back somebody pointed out the stupidity that is $string++ in PHP. What's even more PHP (read: inconsistent) is that $string-- doesn't undo that; it's a NOP.<|eoopr|><|sor|>Referring to [2d9](http://www.reddit.com/r/lolphp/comments/1ofw7t/2d9/)?<|eor|><|sor|>and the fact that these yield different results $a = $b = "2d9"; $a++; $a++; # 2e0 -> 3 $b += 2; # 4<|eor|><|soopr|>Don't forget $a = "0wzz"; $a++;<|eoopr|><|eols|><|endoftext|>
7
lolphp
0xa0000
cd7jswk
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|soopr|>A bit back somebody pointed out the stupidity that is $string++ in PHP. What's even more PHP (read: inconsistent) is that $string-- doesn't undo that; it's a NOP.<|eoopr|><|sor|>Referring to [2d9](http://www.reddit.com/r/lolphp/comments/1ofw7t/2d9/)?<|eor|><|eols|><|endoftext|>
6
lolphp
phoshi
cd7n8ac
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|sor|>Why is $string++ stupid? Plenty of things use that system, for instance excel column names. **EDIT**: I didn't mean in PHP, I meant the general concept. There exists a kind of base-26 notation where the next string after Z is AA and the next string after AZ is AB and so on. String incrementing (for [A-Z] strings) in Perl follows this pattern, rather than erroring or doing nothing. It's not so terrible. PHP, as someone said, copied this feature but got it wrong. <|eor|><|sor|>Well, for one thing: $a = $b = "2D9"; $a++; $a++; $b = $b + 2; Leaves $a as 3, and $b as 4. So, no, not really a sane system by any stretch of the imagination, really.<|eor|><|eols|><|endoftext|>
6
lolphp
ZorbaTHut
cd8aj9j
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|sor|>looks like another perl feature they didnt really manage to port sensibly... just like die() and probably ... everything else?<|eor|><|sor|>\>implying there's any sensible way to increment a string I'm norwegian, I would expect `$a = "z"; print(++$a);` to yield "[](http://www.youtube.com/watch?v=f488uJAQgmw)"<|eor|><|sor|>Solution: Locale-sensitive increment operators! :D :D :D<|eor|><|eols|><|endoftext|>
6
lolphp
dagbrown
cd7yzqy
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|sor|>Why is $string++ stupid? Plenty of things use that system, for instance excel column names. **EDIT**: I didn't mean in PHP, I meant the general concept. There exists a kind of base-26 notation where the next string after Z is AA and the next string after AZ is AB and so on. String incrementing (for [A-Z] strings) in Perl follows this pattern, rather than erroring or doing nothing. It's not so terrible. PHP, as someone said, copied this feature but got it wrong. <|eor|><|soopr|>Among other things, because of PHP's typing. It results in monstrosities like this: https://eval.in/60685. It also means that $string+1 != $string++. Edit: Also, Excel is hardly an example of a reasonable programming system.<|eoopr|><|sor|>OMG, that string turned into an integer. I just gagged a little bit. This is why I don't like languages with weak typing.<|eor|><|sor|>There are languages with weak typing, and then there are languages with sloppy typing. PHP is the latter. PHP's typing is so sloppy that you may as well describe it as drunken, sleep-deprived typing.<|eor|><|eols|><|endoftext|>
6
lolphp
huf
cd7l7pl
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|sor|>looks like another perl feature they didnt really manage to port sensibly... just like die() and probably ... everything else?<|eor|><|eols|><|endoftext|>
5
lolphp
synt4x
cd85ber
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|sor|>I inherited a project tracker that gave IDs to projects using this scheme (e.g. customer 123 would have projects like 123a, ..., 123z, 123aa, etc). I wanted to claw my eyes out when I was required to port this scheme to a new language.<|eor|><|eols|><|endoftext|>
5
lolphp
huf
cd7n9y4
<|sols|><|sot|>$string++ is stupid, but what's stupider is that $string-- doesn't match<|eot|><|sol|>https://eval.in/60631<|eol|><|sor|>looks like another perl feature they didnt really manage to port sensibly... just like die() and probably ... everything else?<|eor|><|sor|>\>implying there's any sensible way to increment a string I'm norwegian, I would expect `$a = "z"; print(++$a);` to yield "[](http://www.youtube.com/watch?v=f488uJAQgmw)"<|eor|><|sor|>there's many sensible ways to increment a string. this is one of them. but yeah, i dont think this belongs in a basic operator either.<|eor|><|eols|><|endoftext|>
5
lolphp
SockPants
1j3wlz
<|sols|><|sot|>PHP runs object constructor -after- setting variables with mysql_fetch_object, won't fix bug because it might break old code.<|eot|><|sol|>https://bugs.php.net/bug.php?id=46105<|eol|><|eols|><|endoftext|>
41
lolphp
Mych
cbbbzzb
<|sols|><|sot|>PHP runs object constructor -after- setting variables with mysql_fetch_object, won't fix bug because it might break old code.<|eot|><|sol|>https://bugs.php.net/bug.php?id=46105<|eol|><|sor|>That clearly calls for the addition of `mysql_real_fetch_object()`.<|eor|><|eols|><|endoftext|>
28
lolphp
gearvOsh
cbavgg8
<|sols|><|sot|>PHP runs object constructor -after- setting variables with mysql_fetch_object, won't fix bug because it might break old code.<|eot|><|sol|>https://bugs.php.net/bug.php?id=46105<|eol|><|soopr|> object mysql_fetch_object ( resource $result [, string $class_name [, array $params ]] ) This function is pretty useful, except that when you specify the class_name of the object, it runs the constructor *after* filling in the variables. The other way around would obviously be more intuitive, but because it has been done wrong in the first place it apparently can't be changed as people would have built code that relies on this order.<|eoopr|><|sor|>Should be using PDO at this point anyways.<|eor|><|eols|><|endoftext|>
11
lolphp
SockPants
cbatz0j
<|sols|><|sot|>PHP runs object constructor -after- setting variables with mysql_fetch_object, won't fix bug because it might break old code.<|eot|><|sol|>https://bugs.php.net/bug.php?id=46105<|eol|><|soopr|> object mysql_fetch_object ( resource $result [, string $class_name [, array $params ]] ) This function is pretty useful, except that when you specify the class_name of the object, it runs the constructor *after* filling in the variables. The other way around would obviously be more intuitive, but because it has been done wrong in the first place it apparently can't be changed as people would have built code that relies on this order.<|eoopr|><|eols|><|endoftext|>
8
lolphp
cfreak2399
cbawybk
<|sols|><|sot|>PHP runs object constructor -after- setting variables with mysql_fetch_object, won't fix bug because it might break old code.<|eot|><|sol|>https://bugs.php.net/bug.php?id=46105<|eol|><|soopr|> object mysql_fetch_object ( resource $result [, string $class_name [, array $params ]] ) This function is pretty useful, except that when you specify the class_name of the object, it runs the constructor *after* filling in the variables. The other way around would obviously be more intuitive, but because it has been done wrong in the first place it apparently can't be changed as people would have built code that relies on this order.<|eoopr|><|sor|>Should be using PDO at this point anyways.<|eor|><|sor|>Or mysqli which is a wtf in itself that they didn't just make one generic database handler. But yeah no need to fix this bug now as the mysql_* interface is deprecated. <|eor|><|eols|><|endoftext|>
7
lolphp
AnonymousPHPDevelope
1b6dys
<|sols|><|sot|>Fun with $this: Guess the output<|eot|><|sol|>http://www.phpfiddle.org/lite/code/1wb-ydp<|eol|><|eols|><|endoftext|>
48
lolphp
huf
c941r2e
<|sols|><|sot|>Fun with $this: Guess the output<|eot|><|sol|>http://www.phpfiddle.org/lite/code/1wb-ydp<|eol|><|sor|>this is pure fucking joy.<|eor|><|eols|><|endoftext|>
13
lolphp
polish_niceguy
c94clv8
<|sols|><|sot|>Fun with $this: Guess the output<|eot|><|sol|>http://www.phpfiddle.org/lite/code/1wb-ydp<|eol|><|sor|>But who was foo?!?!?!?!?!?!!!<|eor|><|sor|> $foo = 'this'; $$foo = 'Dog'; echo "Yes, this is $this";<|eor|><|eols|><|endoftext|>
9
lolphp
catcradle5
c948ikf
<|sols|><|sot|>Fun with $this: Guess the output<|eot|><|sol|>http://www.phpfiddle.org/lite/code/1wb-ydp<|eol|><|sor|>But who was foo?!?!?!?!?!?!!!<|eor|><|eols|><|endoftext|>
7
lolphp
arcanin
4l0p76
<|sols|><|sot|>PHP is not able to read multipart/form-data with anything else than POST (PATCH, PUT, anyone?)<|eot|><|sol|>https://bugs.php.net/bug.php?id=55815<|eol|><|eols|><|endoftext|>
45
lolphp
beardedlinuxgeek
d3jilun
<|sols|><|sot|>PHP is not able to read multipart/form-data with anything else than POST (PATCH, PUT, anyone?)<|eot|><|sol|>https://bugs.php.net/bug.php?id=55815<|eol|><|sor|>It makes more sense to access the input stream anyways. file_get_contents('php://input'); It's the only way to pass true JSON objects back and forth, instead of using formurlencoded nonsense.<|eor|><|eols|><|endoftext|>
17
lolphp
kageurufu
d3jpsan
<|sols|><|sot|>PHP is not able to read multipart/form-data with anything else than POST (PATCH, PUT, anyone?)<|eot|><|sol|>https://bugs.php.net/bug.php?id=55815<|eol|><|sor|>It makes more sense to access the input stream anyways. file_get_contents('php://input'); It's the only way to pass true JSON objects back and forth, instead of using formurlencoded nonsense.<|eor|><|sor|>The issue was specifically for multipart/form-data, not application/json Yeah, reading php://input is the proper way to handle JSON request bodies, but you can't do a file upload with JSON. What if you need to PUT an image to replace an entity on the server, with clientside provided metadata? The issue is completely valid.<|eor|><|eols|><|endoftext|>
11
lolphp
gsnedders
d3jo6fp
<|sols|><|sot|>PHP is not able to read multipart/form-data with anything else than POST (PATCH, PUT, anyone?)<|eot|><|sol|>https://bugs.php.net/bug.php?id=55815<|eol|><|sor|>Opened: 2011 Status: open total PHP<|eor|><|sor|>Is there any major project that doesn't have years old bugs still open? Well, I guess those that auto-close them with a comment "if this bug still exists, please report it again"<|eor|><|eols|><|endoftext|>
11
lolphp
arcanin
d3javr3
<|sols|><|sot|>PHP is not able to read multipart/form-data with anything else than POST (PATCH, PUT, anyone?)<|eot|><|sol|>https://bugs.php.net/bug.php?id=55815<|eol|><|soopr|>And that bug has been opened since 2011. I'm baffled. Worse thing is, they seem to be hiding behind some kind of excuse instead of fixing the issue. > Second, I want to point out that what you're asking is actually a violation of the HTTP specification as per RFC 2616 specifically Section 9.6 > > [... proceed to quote something completely off topic about *URIs* ...] <|eoopr|><|eols|><|endoftext|>
10
lolphp
shvelo
d3jncz2
<|sols|><|sot|>PHP is not able to read multipart/form-data with anything else than POST (PATCH, PUT, anyone?)<|eot|><|sol|>https://bugs.php.net/bug.php?id=55815<|eol|><|sor|>Opened: 2011 Status: open total PHP<|eor|><|eols|><|endoftext|>
6
lolphp
arcanin
d3kag7x
<|sols|><|sot|>PHP is not able to read multipart/form-data with anything else than POST (PATCH, PUT, anyone?)<|eot|><|sol|>https://bugs.php.net/bug.php?id=55815<|eol|><|sor|>That's a misleading title. The linked bug report is about the $_POST super-global only working with POST requests. As [beardedlinuxgeek](https://www.reddit.com/r/lolphp/comments/4l0p76/php_is_not_able_to_read_multipartformdata_with/d3jilun) points out, it is possible to read the multipart/form-data from PHP.<|eor|><|soopr|>It is indeed possible to read it. It just isn't possible to parse it. At least not natively.<|eoopr|><|sor|> $postData = array(); $postDataString = file_get_contents('php://input'); if(mb_strlen($postDataString) > 0) { $postDataStrings = explode('&', $postDataString); foreach($postDataStrings as $postDataFieldString) { list($key, $value) = explode('=', $postDataFieldString, 2); $postData[urldecode($key)] = urldecode($value); } } print_r($postData);<|eor|><|soopr|>Do you actually suggest using urldecode to parse binary data? <|eoopr|><|eols|><|endoftext|>
6
lolphp
PhantomRacer
d3jjyfw
<|sols|><|sot|>PHP is not able to read multipart/form-data with anything else than POST (PATCH, PUT, anyone?)<|eot|><|sol|>https://bugs.php.net/bug.php?id=55815<|eol|><|sor|>That's a misleading title. The linked bug report is about the $_POST super-global only working with POST requests. As [beardedlinuxgeek](https://www.reddit.com/r/lolphp/comments/4l0p76/php_is_not_able_to_read_multipartformdata_with/d3jilun) points out, it is possible to read the multipart/form-data from PHP.<|eor|><|eols|><|endoftext|>
5
lolphp
phoshi
d3kq2hj
<|sols|><|sot|>PHP is not able to read multipart/form-data with anything else than POST (PATCH, PUT, anyone?)<|eot|><|sol|>https://bugs.php.net/bug.php?id=55815<|eol|><|sor|>It makes more sense to access the input stream anyways. file_get_contents('php://input'); It's the only way to pass true JSON objects back and forth, instead of using formurlencoded nonsense.<|eor|><|sor|>The issue was specifically for multipart/form-data, not application/json Yeah, reading php://input is the proper way to handle JSON request bodies, but you can't do a file upload with JSON. What if you need to PUT an image to replace an entity on the server, with clientside provided metadata? The issue is completely valid.<|eor|><|sor|>I mean modern browser with the [`FileReader`](https://developer.mozilla.org/en-US/docs/Web/API/FileReader) API can totally do that without using multipart/form-data. In some ways I would find this preferable, but I also wouldn't use PHP and I'd probably want to support multipart/form-data on my backend server (so it's easier to use the API with `curl` and whatnot)<|eor|><|sor|>I don't see how the `FileReader` API changes the way the file is sent to the server. Does it imply that the files are sent as something different than "multipart/form-data"?<|eor|><|sor|>no FileReader lets javascript read the binary file in as a ByteArray, (or text or a data url, etc) then you can do whatever you want with it (like upload via AJAX). It doesn't do any uploading on it's own.<|eor|><|sor|>That seems like it would massively increase the complexity of what you're doing, as well as making it impossible to use without JS and needlessly difficult to integrate with other tooling.<|eor|><|sor|>Indeed, but you can make it look/feel real nice if you put the effort in.<|eor|><|sor|>Sure, but it isn't a replacement for your browser's implementation of multipart/form-data. It's a much lower level tool with which you could reimplement things like multipart/form-data, and if the only reason you're using it is because your language doesn't let you parse multipart/form-data then you're getting a lot of losses and very few gains.<|eor|><|eols|><|endoftext|>
5
lolphp
sarciszewski
40l851
<|sols|><|sot|>#define PHP_CRYPT_RAND php_rand()<|eot|><|sol|>https://twitter.com/voodooKobra/status/686790169836568576<|eol|><|eols|><|endoftext|>
43
lolphp
myaut
cyv4z2y
<|sols|><|sot|>#define PHP_CRYPT_RAND php_rand()<|eot|><|sol|>https://twitter.com/voodooKobra/status/686790169836568576<|eol|><|sor|>Comment above is also golden: /* If the configure-time checks fail, we provide DES. * XXX: This is a hack. Fix the real problem! */<|eor|><|eols|><|endoftext|>
23
lolphp
sarciszewski
cyvad1y
<|sols|><|sot|>#define PHP_CRYPT_RAND php_rand()<|eot|><|sol|>https://twitter.com/voodooKobra/status/686790169836568576<|eol|><|sor|>oh noes! The (public) salt is generated using a non-cryptographic RNG. Stop the presses and start the panic! (I'm talking about the [second link](https://github.com/php/php-src/blob/71c19800258ee3a9548af9a5e64ab0a62d1b1d8e/ext/standard/crypt.c#L308-L312) in that tweet<|eor|><|soopr|>Calling something `CRYPT_RAND` then using a non-cryptographic PRNG is pretty fail. The second link was just to show that it does actually get used.<|eoopr|><|eols|><|endoftext|>
15
lolphp
barubary
cyvbwhp
<|sols|><|sot|>#define PHP_CRYPT_RAND php_rand()<|eot|><|sol|>https://twitter.com/voodooKobra/status/686790169836568576<|eol|><|sor|>oh noes! The (public) salt is generated using a non-cryptographic RNG. Stop the presses and start the panic! (I'm talking about the [second link](https://github.com/php/php-src/blob/71c19800258ee3a9548af9a5e64ab0a62d1b1d8e/ext/standard/crypt.c#L308-L312) in that tweet<|eor|><|soopr|>Calling something `CRYPT_RAND` then using a non-cryptographic PRNG is pretty fail. The second link was just to show that it does actually get used.<|eoopr|><|sor|>I suspect it was named for `crypt()`, not actual crypto.<|eor|><|eols|><|endoftext|>
10
lolphp
the_alias_of_andrea
cywk9ib
<|sols|><|sot|>#define PHP_CRYPT_RAND php_rand()<|eot|><|sol|>https://twitter.com/voodooKobra/status/686790169836568576<|eol|><|sor|>Ah yes, mcrypt, which provides the World War II German Enigma cipher as an option.<|eor|><|eols|><|endoftext|>
9
lolphp
sarciszewski
cyvc2lo
<|sols|><|sot|>#define PHP_CRYPT_RAND php_rand()<|eot|><|sol|>https://twitter.com/voodooKobra/status/686790169836568576<|eol|><|sor|>oh noes! The (public) salt is generated using a non-cryptographic RNG. Stop the presses and start the panic! (I'm talking about the [second link](https://github.com/php/php-src/blob/71c19800258ee3a9548af9a5e64ab0a62d1b1d8e/ext/standard/crypt.c#L308-L312) in that tweet<|eor|><|soopr|>Calling something `CRYPT_RAND` then using a non-cryptographic PRNG is pretty fail. The second link was just to show that it does actually get used.<|eoopr|><|sor|>I suspect it was named for `crypt()`, not actual crypto.<|eor|><|soopr|>Your suspicion is correct, but does explaining the joke make it less funny?<|eoopr|><|eols|><|endoftext|>
9
lolphp
vytah
cz2x0rw
<|sols|><|sot|>#define PHP_CRYPT_RAND php_rand()<|eot|><|sol|>https://twitter.com/voodooKobra/status/686790169836568576<|eol|><|sor|>Ah yes, mcrypt, which provides the World War II German Enigma cipher as an option.<|eor|><|sor|>[I thought you were joking...](http://php.net/manual/en/mcrypt.ciphers.php) Also, as the *downvoted* comment there hints, and other pieces of documentation confirm, mcrypt doesn't support any nul-safe padding, making it unusable for encrypting binary data, and for interoperability. Luckily, mcrypt is deprecated.<|eor|><|eols|><|endoftext|>
8
lolphp
ltldvl
3di02g
<|sols|><|sot|>Using exceptions inside usort() callback function causes a warning<|eot|><|sol|>https://bugs.php.net/bug.php?id=50688<|eol|><|eols|><|endoftext|>
41
lolphp
HildartheDorf
ct5hm2y
<|sols|><|sot|>Using exceptions inside usort() callback function causes a warning<|eot|><|sol|>https://bugs.php.net/bug.php?id=50688<|eol|><|sor|>All because throwing an exception causes a stacktrace. stacktraces cause references. And usort warns if the reference count changes. Relying on implementation details: the language.<|eor|><|eols|><|endoftext|>
34
lolphp
cbraga
ct5qdwv
<|sols|><|sot|>Using exceptions inside usort() callback function causes a warning<|eot|><|sol|>https://bugs.php.net/bug.php?id=50688<|eol|><|sor|>All because throwing an exception causes a stacktrace. stacktraces cause references. And usort warns if the reference count changes. Relying on implementation details: the language.<|eor|><|sor|>I was going to downvote this because it seemed just like an ordinary bug then I read the rationale. > The problem seems to be that usort checks the amount of references before and after the function call to see if the user-provided function modified it Flawless logic, keeping a constant reference count is guarantee that a variable is immutable. The universe says so. Proposed fix: find and drop any one of the references bringing the total back to the original number. State roll back guaranteed.<|eor|><|eols|><|endoftext|>
19
lolphp
arood
ct6bygb
<|sols|><|sot|>Using exceptions inside usort() callback function causes a warning<|eot|><|sol|>https://bugs.php.net/bug.php?id=50688<|eol|><|sor|>I was a bit tired when I read this title and thought it was "Using exceptions inside sort() callback function causes global warming"<|eor|><|eols|><|endoftext|>
7
lolphp
smog_alado
ct6ej1u
<|sols|><|sot|>Using exceptions inside usort() callback function causes a warning<|eot|><|sol|>https://bugs.php.net/bug.php?id=50688<|eol|><|sor|>All because throwing an exception causes a stacktrace. stacktraces cause references. And usort warns if the reference count changes. Relying on implementation details: the language.<|eor|><|sor|>According to one of the comments, you don't need to throw an exception. Just creating an exception object is enough. function comp($a,$b){ @new Exception("dupa"); }<|eor|><|eols|><|endoftext|>
6
lolphp
polish_niceguy
ct6ctho
<|sols|><|sot|>Using exceptions inside usort() callback function causes a warning<|eot|><|sol|>https://bugs.php.net/bug.php?id=50688<|eol|><|sor|>All because throwing an exception causes a stacktrace. stacktraces cause references. And usort warns if the reference count changes. Relying on implementation details: the language.<|eor|><|sor|>I was going to downvote this because it seemed just like an ordinary bug then I read the rationale. > The problem seems to be that usort checks the amount of references before and after the function call to see if the user-provided function modified it Flawless logic, keeping a constant reference count is guarantee that a variable is immutable. The universe says so. Proposed fix: find and drop any one of the references bringing the total back to the original number. State roll back guaranteed.<|eor|><|sor|>Don't give them more ideas.<|eor|><|eols|><|endoftext|>
6
lolphp
ElusiveGuy
ct6gqk1
<|sols|><|sot|>Using exceptions inside usort() callback function causes a warning<|eot|><|sol|>https://bugs.php.net/bug.php?id=50688<|eol|><|sor|>I was a bit tired when I read this title and thought it was "Using exceptions inside sort() callback function causes global warming"<|eor|><|sor|>> "Sorry, we cannot change this behaviour because our users rely on the additional heat produced by exceptions inside usort() to keep their equipment from freezing."<|eor|><|sor|>https://xkcd.com/1172/<|eor|><|eols|><|endoftext|>
6
lolphp
xkcd_transcriber
ct6gqt2
<|sols|><|sot|>Using exceptions inside usort() callback function causes a warning<|eot|><|sol|>https://bugs.php.net/bug.php?id=50688<|eol|><|sor|>I was a bit tired when I read this title and thought it was "Using exceptions inside sort() callback function causes global warming"<|eor|><|sor|>> "Sorry, we cannot change this behaviour because our users rely on the additional heat produced by exceptions inside usort() to keep their equipment from freezing."<|eor|><|sor|>https://xkcd.com/1172/<|eor|><|sor|>[Image](http://imgs.xkcd.com/comics/workflow.png) **Title:** Workflow **Title-text:** There are probably children out there holding down spacebar to stay warm in the winter! YOUR UPDATE MURDERS CHILDREN. [Comic Explanation](http://www.explainxkcd.com/wiki/index.php/1172#Explanation) **Stats:** This comic has been referenced 388 times, representing 0.5339% of referenced xkcds. --- ^[xkcd.com](http://www.xkcd.com) ^| ^[xkcdsub](http://www.reddit.com/r/xkcd/) ^| ^[Problems/Bugs?](http://www.reddit.com/r/xkcd_transcriber/) ^| ^[Statistics](http://xkcdref.info/statistics/) ^| ^[StopReplying](http://reddit.com/message/compose/?to=xkcd_transcriber&subject=ignore%20me&message=ignore%20me) ^| ^[Delete](http://reddit.com/message/compose/?to=xkcd_transcriber&subject=delete&message=delete%20t1_ct6gqt2)<|eor|><|eols|><|endoftext|>
5
lolphp
i_make_snow_flakes
2l1g7s
<|sols|><|sot|>Prepared statements in pdo, running in emulated mode (which is default), will split the query on semi colons, and execute multiple queries thus formed, allowing SQL injection attacks and was the basis on the last Drupal vulnerability.<|eot|><|sol|>http://blog.ircmaxell.com/2014/10/a-lesson-in-security.html<|eol|><|eols|><|endoftext|>
45
lolphp
allthediamonds
clqphba
<|sols|><|sot|>Prepared statements in pdo, running in emulated mode (which is default), will split the query on semi colons, and execute multiple queries thus formed, allowing SQL injection attacks and was the basis on the last Drupal vulnerability.<|eot|><|sol|>http://blog.ircmaxell.com/2014/10/a-lesson-in-security.html<|eol|><|sor|>I'm not an expert on PDO, but why is PDO so crucial? Can't I just write: $query = "SELECT * FROM table WHERE userid = '" . $userid . "'"; ...and as long as I replace all problematic characters (" ' ` \ etc.) in $userid BEFORE it is added to $query, shouldn't that make the query immune to manipulation? For example: $userid = "' OR user != ''; DROP table;"; would turn into this if I replaced ' with `: $userid = "` OR user != ``; DROP table;"; And this would occur BEFORE it gets placed in $query. I mean, you may be able to still get junk data input if this is ALL you do before it hits the database, but no actual $query variable manipulation can occur. I couldn't send a command to drop a table or do something else.<|eor|><|sor|>The whole "escape problematic characters" idea is bullshit; it's the reasoning behind awful ideas like magic quotes. Always use a library that understands the language you're trying to speak and the problem you're trying to solve. The deal is that you don't want the programmer to be responsible for escaping each and every argument, because programmers are forgetful little shits, so you use a prepared statements library. <|eor|><|eols|><|endoftext|>
19
lolphp
Innominate8
clqmgf9
<|sols|><|sot|>Prepared statements in pdo, running in emulated mode (which is default), will split the query on semi colons, and execute multiple queries thus formed, allowing SQL injection attacks and was the basis on the last Drupal vulnerability.<|eot|><|sol|>http://blog.ircmaxell.com/2014/10/a-lesson-in-security.html<|eol|><|sor|>I'm not an expert on PDO, but why is PDO so crucial? Can't I just write: $query = "SELECT * FROM table WHERE userid = '" . $userid . "'"; ...and as long as I replace all problematic characters (" ' ` \ etc.) in $userid BEFORE it is added to $query, shouldn't that make the query immune to manipulation? For example: $userid = "' OR user != ''; DROP table;"; would turn into this if I replaced ' with `: $userid = "` OR user != ``; DROP table;"; And this would occur BEFORE it gets placed in $query. I mean, you may be able to still get junk data input if this is ALL you do before it hits the database, but no actual $query variable manipulation can occur. I couldn't send a command to drop a table or do something else.<|eor|><|sor|>PDO is just one of the better database abstraction options available for PHP. It's parameterized statements(sometimes called prepared statements, the distinction is unimportant here) that matter. > ...and as long as I replace all problematic characters (" ' ` \ etc.) in $userid BEFORE it is added to $query, This is a much harder problem than you think due to character sets and multi-byte encodings. It's also very easy for anyone to miss doing it just once and bam, your site is exposed. Using parameterized statements reduces code complexity, eliminates places where bugs can be inserted, and generally protects the programmer from doing dumb things. With very few exceptions if you're not using a parameterized statement for an SQL query that has parameters, you're doing it wrong.<|eor|><|eols|><|endoftext|>
15
lolphp
catcradle5
clqlrm1
<|sols|><|sot|>Prepared statements in pdo, running in emulated mode (which is default), will split the query on semi colons, and execute multiple queries thus formed, allowing SQL injection attacks and was the basis on the last Drupal vulnerability.<|eot|><|sol|>http://blog.ircmaxell.com/2014/10/a-lesson-in-security.html<|eol|><|sor|>I'm not an expert on PDO, but why is PDO so crucial? Can't I just write: $query = "SELECT * FROM table WHERE userid = '" . $userid . "'"; ...and as long as I replace all problematic characters (" ' ` \ etc.) in $userid BEFORE it is added to $query, shouldn't that make the query immune to manipulation? For example: $userid = "' OR user != ''; DROP table;"; would turn into this if I replaced ' with `: $userid = "` OR user != ``; DROP table;"; And this would occur BEFORE it gets placed in $query. I mean, you may be able to still get junk data input if this is ALL you do before it hits the database, but no actual $query variable manipulation can occur. I couldn't send a command to drop a table or do something else.<|eor|><|sor|>I could write a loooong answer explaining exactly why it's much better to use parameterized queries (which can be done with PDO or another library) instead of trying to used concatenated input. Here's a good answer: http://stackoverflow.com/a/8265319/824544 In simpler terms: prepared statements/PDO, when used correctly without concatenation (Drupal built a string and concatenated it, so they were not using it as intended), are totally safe form SQL injection by default\*, while trying to escape all user input and concatenate it into a query string can lead to false assumptions and mistakes that lead to SQL injection. And in even simpler terms: always have as much separation as possible between data and code. ^\* ^There ^are ^some ^exceptions ^involving ^certain ^multibyte ^encodings ^with ^PDO's ^emulation ^mode.<|eor|><|eols|><|endoftext|>
12