subreddit
stringclasses
7 values
author
stringlengths
3
20
id
stringlengths
5
7
content
stringlengths
67
30.4k
score
int64
0
140k
lolphp
maweki
czybqe4
<|sols|><|sot|>"phpversions.info now highlights PHP versions with known security issues", they could've saved themselves the effort and just painted everything red though<|eot|><|sol|>http://phpversions.info/shared-hosting/<|eol|><|sor|>So all the green ones have unknown security issues?<|eor|><|eols|><|endoftext|>
44
lolphp
tommorris
czykhor
<|sols|><|sot|>"phpversions.info now highlights PHP versions with known security issues", they could've saved themselves the effort and just painted everything red though<|eot|><|sol|>http://phpversions.info/shared-hosting/<|eol|><|sor|>[deleted]<|eor|><|sor|>...and PHP has a culture of shared hosting where those security updates don't get applied because some shady hosting company is more interested in buying stock photos of people in suits looking efficient and answering the telephone than keeping up on all those boring changelogs and security notices.<|eor|><|eols|><|endoftext|>
29
lolphp
Liorithiel
czyerhh
<|sols|><|sot|>"phpversions.info now highlights PHP versions with known security issues", they could've saved themselves the effort and just painted everything red though<|eot|><|sol|>http://phpversions.info/shared-hosting/<|eol|><|sor|>Does it take into consideration that people backport security patches to earlier versions?<|eor|><|sor|>How do you know what a custom patch fixed?<|eor|><|sor|>Distribution changelogs. For example, see [Debian jessie's `php5` package changelog](http://metadata.ftp-master.debian.org/changelogs/main/p/php5/php5_5.6.17+dfsg-0+deb8u1_changelog). Curious thing: the only CVE-qualified security error in PHP 5.6.18 is related to a library the standard PHP distribution bundles, but which is [independently updated in Debian](https://security-tracker.debian.org/tracker/CVE-2015-8383). So, to me it is likely that at this point phpversions.info is basically badmouthing hosting services that actually fix known security issues, while responsibly limiting the scope of changes to existing applications to keep them from accidental breakage. Well, that's a lolphp for you.<|eor|><|eols|><|endoftext|>
9
lolphp
Liorithiel
czydxbd
<|sols|><|sot|>"phpversions.info now highlights PHP versions with known security issues", they could've saved themselves the effort and just painted everything red though<|eot|><|sol|>http://phpversions.info/shared-hosting/<|eol|><|sor|>Does it take into consideration that people backport security patches to earlier versions?<|eor|><|eols|><|endoftext|>
5
lolphp
vytah
czyf6e8
<|sols|><|sot|>"phpversions.info now highlights PHP versions with known security issues", they could've saved themselves the effort and just painted everything red though<|eot|><|sol|>http://phpversions.info/shared-hosting/<|eol|><|sor|>Does it take into consideration that people backport security patches to earlier versions?<|eor|><|sor|>How do you know what a custom patch fixed?<|eor|><|sor|>Distribution changelogs. For example, see [Debian jessie's `php5` package changelog](http://metadata.ftp-master.debian.org/changelogs/main/p/php5/php5_5.6.17+dfsg-0+deb8u1_changelog). Curious thing: the only CVE-qualified security error in PHP 5.6.18 is related to a library the standard PHP distribution bundles, but which is [independently updated in Debian](https://security-tracker.debian.org/tracker/CVE-2015-8383). So, to me it is likely that at this point phpversions.info is basically badmouthing hosting services that actually fix known security issues, while responsibly limiting the scope of changes to existing applications to keep them from accidental breakage. Well, that's a lolphp for you.<|eor|><|sor|>It looks like the Debian package is still normal 5.6.17, with no extra security patches, only modified according to Debian Free Software Guidelines.<|eor|><|eols|><|endoftext|>
5
lolphp
iheartrms
3a3nhi
<|sols|><|sot|>PHP :: Sec Bug #69646 :: OS command injection vulnerability in escapeshellarg<|eot|><|sol|>https://bugs.php.net/bug.php?id=69646<|eol|><|eols|><|endoftext|>
35
lolphp
vytah
cs961f0
<|sols|><|sot|>PHP :: Sec Bug #69646 :: OS command injection vulnerability in escapeshellarg<|eot|><|sol|>https://bugs.php.net/bug.php?id=69646<|eol|><|sor|>Wow. I would have expected at least some kind of convolutedness beyond the backslash in the end. This almsot looks like a unit test one would come up with after writing the first two or so...<|eor|><|sor|>Or you know, it's a Windows only bug so the real flaw is with Windows so PHP has to patch another hole in the massive Windows ship<|eor|><|sor|>Windows' handling of command line parameters is laughable. In fact, there are no command line parameters, there's just one command line and it's up to the application to parse it. And each can do it however it wants. The lolphp is because PHP escapes and parses the command line in two different ways.<|eor|><|eols|><|endoftext|>
21
lolphp
dpoon
cs9c8mu
<|sols|><|sot|>PHP :: Sec Bug #69646 :: OS command injection vulnerability in escapeshellarg<|eot|><|sol|>https://bugs.php.net/bug.php?id=69646<|eol|><|sor|>Wow. I would have expected at least some kind of convolutedness beyond the backslash in the end. This almsot looks like a unit test one would come up with after writing the first two or so...<|eor|><|sor|>Or you know, it's a Windows only bug so the real flaw is with Windows so PHP has to patch another hole in the massive Windows ship<|eor|><|sor|>Windows' handling of command line parameters is laughable. In fact, there are no command line parameters, there's just one command line and it's up to the application to parse it. And each can do it however it wants. The lolphp is because PHP escapes and parses the command line in two different ways.<|eor|><|sor|>No, the lolphp is that `escapeshellcmd()` exists at all. Most other languages don't have such a function. It's needed in PHP because there is a [`system()`](http://php.net/system), but there is no [`exec()`](http://linux.die.net/man/3/exec)-like family of functions where you can pass the command-line arguments as an array. `escapeshellcmd()` is a doomed strategy anyway: how can you be sure that you've escaped all characters correctly for all kinds of shells in existence?<|eor|><|eols|><|endoftext|>
17
lolphp
vytah
cs9czjk
<|sols|><|sot|>PHP :: Sec Bug #69646 :: OS command injection vulnerability in escapeshellarg<|eot|><|sol|>https://bugs.php.net/bug.php?id=69646<|eol|><|sor|>Wow. I would have expected at least some kind of convolutedness beyond the backslash in the end. This almsot looks like a unit test one would come up with after writing the first two or so...<|eor|><|sor|>Or you know, it's a Windows only bug so the real flaw is with Windows so PHP has to patch another hole in the massive Windows ship<|eor|><|sor|>Windows' handling of command line parameters is laughable. In fact, there are no command line parameters, there's just one command line and it's up to the application to parse it. And each can do it however it wants. The lolphp is because PHP escapes and parses the command line in two different ways.<|eor|><|sor|>Really, that isn't any different from how Linux does it. In C, you only get an array of `char*`s (`argv`), along with an int telling you how many arguments there are (`argc`). From there, in Linux too, it's up to the application to parse that into parameters and such. Now, most *nix systems, including Linux and the BSDs, have a `getopt` library which they can include, which you can pass `argv` and `argc` to, and get back your flags and such. Windows also seems to come with such a library to parse command line options for .NET in C#: http://www.ndesk.org/Options<|eor|><|sor|>On windows, there really is just one command line string. Microsoft's libc will parse it (GetCommandLineA) and then invoke main. If the program uses WinMain, you have to parse it yourself. On Unix, you can use the fork+exec pattern to set the argv array to be exactly as needed, bypassing the shell. The parsing that happens when you call system specifically is done by the shell before invoking the program, but the program receives its arguments after parsing. You, of course, still need to parse the parameters to figure out what they mean, but all the white space splitting and character escaping has to be guessed by the libc on windows, while none of that is needed on exec.<|eor|><|sor|>In other words: On Unix, you pass `{"a", "b"}` and the programs know the arguments exactly. On Windows, you pass `"a b"` and the programs have to know how to build and parse this string.<|eor|><|eols|><|endoftext|>
17
lolphp
andsens
cs8zpdh
<|sols|><|sot|>PHP :: Sec Bug #69646 :: OS command injection vulnerability in escapeshellarg<|eot|><|sol|>https://bugs.php.net/bug.php?id=69646<|eol|><|sor|>Wow. I would have expected at least some kind of convolutedness beyond the backslash in the end. This almsot looks like a unit test one would come up with after writing the first two or so...<|eor|><|eols|><|endoftext|>
13
lolphp
gu3st12
cs91jwx
<|sols|><|sot|>PHP :: Sec Bug #69646 :: OS command injection vulnerability in escapeshellarg<|eot|><|sol|>https://bugs.php.net/bug.php?id=69646<|eol|><|sor|>Wow. I would have expected at least some kind of convolutedness beyond the backslash in the end. This almsot looks like a unit test one would come up with after writing the first two or so...<|eor|><|sor|>Or you know, it's a Windows only bug so the real flaw is with Windows so PHP has to patch another hole in the massive Windows ship<|eor|><|eols|><|endoftext|>
10
lolphp
kovensky
cs9b14p
<|sols|><|sot|>PHP :: Sec Bug #69646 :: OS command injection vulnerability in escapeshellarg<|eot|><|sol|>https://bugs.php.net/bug.php?id=69646<|eol|><|sor|>Wow. I would have expected at least some kind of convolutedness beyond the backslash in the end. This almsot looks like a unit test one would come up with after writing the first two or so...<|eor|><|sor|>Or you know, it's a Windows only bug so the real flaw is with Windows so PHP has to patch another hole in the massive Windows ship<|eor|><|sor|>Windows' handling of command line parameters is laughable. In fact, there are no command line parameters, there's just one command line and it's up to the application to parse it. And each can do it however it wants. The lolphp is because PHP escapes and parses the command line in two different ways.<|eor|><|sor|>Really, that isn't any different from how Linux does it. In C, you only get an array of `char*`s (`argv`), along with an int telling you how many arguments there are (`argc`). From there, in Linux too, it's up to the application to parse that into parameters and such. Now, most *nix systems, including Linux and the BSDs, have a `getopt` library which they can include, which you can pass `argv` and `argc` to, and get back your flags and such. Windows also seems to come with such a library to parse command line options for .NET in C#: http://www.ndesk.org/Options<|eor|><|sor|>On windows, there really is just one command line string. Microsoft's libc will parse it (GetCommandLineA) and then invoke main. If the program uses WinMain, you have to parse it yourself. On Unix, you can use the fork+exec pattern to set the argv array to be exactly as needed, bypassing the shell. The parsing that happens when you call system specifically is done by the shell before invoking the program, but the program receives its arguments after parsing. You, of course, still need to parse the parameters to figure out what they mean, but all the white space splitting and character escaping has to be guessed by the libc on windows, while none of that is needed on exec.<|eor|><|eols|><|endoftext|>
10
lolphp
OneWingedShark
csa1pwv
<|sols|><|sot|>PHP :: Sec Bug #69646 :: OS command injection vulnerability in escapeshellarg<|eot|><|sol|>https://bugs.php.net/bug.php?id=69646<|eol|><|sor|>Wow. I would have expected at least some kind of convolutedness beyond the backslash in the end. This almsot looks like a unit test one would come up with after writing the first two or so...<|eor|><|sor|>Or you know, it's a Windows only bug so the real flaw is with Windows so PHP has to patch another hole in the massive Windows ship<|eor|><|sor|>Windows' handling of command line parameters is laughable. In fact, there are no command line parameters, there's just one command line and it's up to the application to parse it. And each can do it however it wants. The lolphp is because PHP escapes and parses the command line in two different ways.<|eor|><|sor|>Really, that isn't any different from how Linux does it. In C, you only get an array of `char*`s (`argv`), along with an int telling you how many arguments there are (`argc`). From there, in Linux too, it's up to the application to parse that into parameters and such. Now, most *nix systems, including Linux and the BSDs, have a `getopt` library which they can include, which you can pass `argv` and `argc` to, and get back your flags and such. Windows also seems to come with such a library to parse command line options for .NET in C#: http://www.ndesk.org/Options<|eor|><|sor|>On windows, there really is just one command line string. Microsoft's libc will parse it (GetCommandLineA) and then invoke main. If the program uses WinMain, you have to parse it yourself. On Unix, you can use the fork+exec pattern to set the argv array to be exactly as needed, bypassing the shell. The parsing that happens when you call system specifically is done by the shell before invoking the program, but the program receives its arguments after parsing. You, of course, still need to parse the parameters to figure out what they mean, but all the white space splitting and character escaping has to be guessed by the libc on windows, while none of that is needed on exec.<|eor|><|sor|>In other words: On Unix, you pass `{"a", "b"}` and the programs know the arguments exactly. On Windows, you pass `"a b"` and the programs have to know how to build and parse this string.<|eor|><|sor|>[deleted]<|eor|><|sor|>In Unix the asterisk is expanded by the shell... this resulted in a lot of pain/frustration and ugly workarounds to get the actual as-typed commands. I *think* Linux inherited this, but I'm not 100% sure. Check out the [Unix-Hater's Handbook](http://www.csf.ac.at/fileadmin/user_upload/BioComp/training/unix_haters_handbook.pdf) for some interesting look into the [mis]design of Unix and many Unix-like OSes. (Keep in mind that it is rather old, you will likely be surprised by how much of the book is still relevant to some degree with modern \*nix.)<|eor|><|eols|><|endoftext|>
8
lolphp
mort96
cs97z3f
<|sols|><|sot|>PHP :: Sec Bug #69646 :: OS command injection vulnerability in escapeshellarg<|eot|><|sol|>https://bugs.php.net/bug.php?id=69646<|eol|><|sor|>Wow. I would have expected at least some kind of convolutedness beyond the backslash in the end. This almsot looks like a unit test one would come up with after writing the first two or so...<|eor|><|sor|>Or you know, it's a Windows only bug so the real flaw is with Windows so PHP has to patch another hole in the massive Windows ship<|eor|><|sor|>Windows' handling of command line parameters is laughable. In fact, there are no command line parameters, there's just one command line and it's up to the application to parse it. And each can do it however it wants. The lolphp is because PHP escapes and parses the command line in two different ways.<|eor|><|sor|>Really, that isn't any different from how Linux does it. In C, you only get an array of `char*`s (`argv`), along with an int telling you how many arguments there are (`argc`). From there, in Linux too, it's up to the application to parse that into parameters and such. Now, most *nix systems, including Linux and the BSDs, have a `getopt` library which they can include, which you can pass `argv` and `argc` to, and get back your flags and such. Windows also seems to come with such a library to parse command line options for .NET in C#: http://www.ndesk.org/Options<|eor|><|eols|><|endoftext|>
7
lolphp
huf
2zd5d7
<|sols|><|sot|>list() splits strings if they come out of reset()?!<|eot|><|sol|>http://3v4l.org/Ha1FX<|eol|><|eols|><|endoftext|>
38
lolphp
allthediamonds
cphxubq
<|sols|><|sot|>list() splits strings if they come out of reset()?!<|eot|><|sol|>http://3v4l.org/Ha1FX<|eol|><|soopr|>list() also seems to split if the string comes from a variable instead of a literal. what. the. fuck.<|eoopr|><|sor|>http://3v4l.org/tlABL WHAAAAT. What.<|eor|><|eols|><|endoftext|>
30
lolphp
huf
cphsuez
<|sols|><|sot|>list() splits strings if they come out of reset()?!<|eot|><|sol|>http://3v4l.org/Ha1FX<|eol|><|soopr|>list() also seems to split if the string comes from a variable instead of a literal. what. the. fuck.<|eoopr|><|eols|><|endoftext|>
20
lolphp
CliffEdgeOrg
cphz66q
<|sols|><|sot|>list() splits strings if they come out of reset()?!<|eot|><|sol|>http://3v4l.org/Ha1FX<|eol|><|sor|>Well.. I'm not an expert(tm) but we can guess some explanation if you know that you can access consecutive letters of a string variable in an array notation like this: $var = "dupa"; echo $var[0].$var[2]; // prints: dp It was *probably* made possible a long time ago to mimic the behavior of "strings" in C: char var[] = "dupa"; printf("%c%c", var[0], var[2]); // prints: dp And it is of course pretty useful (to iterate over letters for example). That's why probably list($x, $y) = $var; works with string vars even it was intended to work with array, as arrays use the same notation to access their elements. Why list($x, $y) = "dupa"; does not work? Well.. String and array dereferencing [is possible since PHP 5.5](http://php.net/migration55.new-features#migration55.new-features.const-dereferencing) so you can write: echo "dupa"[1]; // prints: u echo ["du", "pa"][1]; // prints: pa Maybe while making an implementation for that feature no one thought of updating the list instruction as it was intended to work with arrays.. You should note that your example of list($x, $y) = $var; does not work on "php7@20141101 - 20150301" (gives null as it should) which is the latest of php7. I don't know which change "fixed" that, maybe [uniform variable syntax](https://wiki.php.net/rfc/uniform_variable_syntax) or [abstract syntax tree](https://wiki.php.net/rfc/abstract_syntax_tree), dunno. Of course you can still do list($x, $y) = ["foo", "bar"]; because, well, it's an array right? <|eor|><|eols|><|endoftext|>
17
lolphp
moartoast
cpih6se
<|sols|><|sot|>list() splits strings if they come out of reset()?!<|eot|><|sol|>http://3v4l.org/Ha1FX<|eol|><|soopr|>list() also seems to split if the string comes from a variable instead of a literal. what. the. fuck.<|eoopr|><|sor|>http://3v4l.org/tlABL WHAAAAT. What.<|eor|><|sor|>... good grief<|eor|><|eols|><|endoftext|>
9
lolphp
Various_Pickles
cpjktdy
<|sols|><|sot|>list() splits strings if they come out of reset()?!<|eot|><|sol|>http://3v4l.org/Ha1FX<|eol|><|sor|>So, PHP looked at String.split(), varargs, and tuples in other languages and came up with syntax that manages to be a fucked up mush of all of them at once?<|eor|><|eols|><|endoftext|>
5
lolphp
McGlockenshire
2hgpkq
<|sols|><|sot|>namespace foo { use const true as false; var_dump(false); } // WHY, PHP!? WHY!?<|eot|><|sol|>http://www.reddit.com/r/PHP/comments/2hf8q0/what_is_the_difference_between_while_true_vs/cksasrj<|eol|><|eols|><|endoftext|>
38
lolphp
jadkik94
ckshfoo
<|sols|><|sot|>namespace foo { use const true as false; var_dump(false); } // WHY, PHP!? WHY!?<|eot|><|sol|>http://www.reddit.com/r/PHP/comments/2hf8q0/what_is_the_difference_between_while_true_vs/cksasrj<|eol|><|sor|>You beat me to it by 3 minutes! The funniest thing is this though: > I plan to fix this for PHP 7<|eor|><|eols|><|endoftext|>
22
lolphp
ZiggyTheHamster
cksp4yi
<|sols|><|sot|>namespace foo { use const true as false; var_dump(false); } // WHY, PHP!? WHY!?<|eot|><|sol|>http://www.reddit.com/r/PHP/comments/2hf8q0/what_is_the_difference_between_while_true_vs/cksasrj<|eol|><|sor|>I think the more confusing part is why `false` and `\false` are different. That makes zero sense. Why add the extra `\` character every single time you really mean `false` when they could just make `false` always be `false` because nobody wants `false` to equal something else. Seriously, WTF.<|eor|><|eols|><|endoftext|>
15
lolphp
vytah
cksiwam
<|sols|><|sot|>namespace foo { use const true as false; var_dump(false); } // WHY, PHP!? WHY!?<|eot|><|sol|>http://www.reddit.com/r/PHP/comments/2hf8q0/what_is_the_difference_between_while_true_vs/cksasrj<|eol|><|sor|>The author of that comment is the same guy as in here: http://www.reddit.com/r/lolphp/comments/2h9nhp/optimizing_opcodes_in_a_library_targeted_at/<|eor|><|eols|><|endoftext|>
8
lolphp
McGlockenshire
cksjptf
<|sols|><|sot|>namespace foo { use const true as false; var_dump(false); } // WHY, PHP!? WHY!?<|eot|><|sol|>http://www.reddit.com/r/PHP/comments/2hf8q0/what_is_the_difference_between_while_true_vs/cksasrj<|eol|><|sor|>The author of that comment is the same guy as in here: http://www.reddit.com/r/lolphp/comments/2h9nhp/optimizing_opcodes_in_a_library_targeted_at/<|eor|><|soopr|>Yeah, he's brilliantly insane.<|eoopr|><|eols|><|endoftext|>
6
lolphp
GandhiNotGhandi
cksq62y
<|sols|><|sot|>namespace foo { use const true as false; var_dump(false); } // WHY, PHP!? WHY!?<|eot|><|sol|>http://www.reddit.com/r/PHP/comments/2hf8q0/what_is_the_difference_between_while_true_vs/cksasrj<|eol|><|sor|>[deleted]<|eor|><|sor|>[This seems to be the case.](http://3v4l.org/VLj2Q)<|eor|><|eols|><|endoftext|>
5
lolphp
ZiggyTheHamster
ckxxnhd
<|sols|><|sot|>namespace foo { use const true as false; var_dump(false); } // WHY, PHP!? WHY!?<|eot|><|sol|>http://www.reddit.com/r/PHP/comments/2hf8q0/what_is_the_difference_between_while_true_vs/cksasrj<|eol|><|sor|>I think the more confusing part is why `false` and `\false` are different. That makes zero sense. Why add the extra `\` character every single time you really mean `false` when they could just make `false` always be `false` because nobody wants `false` to equal something else. Seriously, WTF.<|eor|><|sor|>> I think the more confusing part is why false and \false are different. That makes zero sense. **Why add the extra \ character every single time you really mean false when they could just make false always be false because nobody wants false to equal something else.** > > > > Seriously, WTF. Well... there are some cases where you'd want something similar to what you're describing; however, they get down to very machine-/architecture-dependent details. Consider a CPU which has no-voltage signalling 1/true; in communicating with such a system the values sent will be inverted and we would then need either (a) a bitwise inverter, or (b) to communicate in other computers's terms -- in such a case [b] defining 0 as true and 1 as false is certainly a valid approach. Another would be something like USB which, depending on the state, physically-on and -off can mean either 0 or 1 (see [this](http://www.beyondlogic.org/usbnutshell/usb2.shtml#Electrical)) and in such a case it might be beneficial to have `True` and `False` be functions that return the proper value. (Say in a simulator or diagnostic software.)<|eor|><|sor|>PHP is a scripting language and has no reason to give a shit. If you care about those details, use C. True, it might make sense for true/false to be a function that represents the hardware true/false, but PHP is not the language to do that in. You can't just extend TrueClass in PHP like you can in Ruby. I also think that it'd be logical to call hardware true/false by a constant name - `HW_TRUE` or `HW_FALSE` (or `HW_HIGH`/`HW_LOW`). True being 0 and false being nonzero is common. Usually you return an error code - 0 being OK (`E_OK`) and >0 being something else. You wouldn't want to map those values to PHP builtins. That's just weird.<|eor|><|eols|><|endoftext|>
5
lolphp
Rangi42
2fxgu7
<|sols|><|sot|>The Codeless Code: Case 161: Triangle ("the Abbey of Hidden Absurdities, where PHP is written")<|eot|><|sol|>http://thecodelesscode.com/case/161<|eol|><|eols|><|endoftext|>
38
lolphp
Rangi42
ckdq7lx
<|sols|><|sot|>The Codeless Code: Case 161: Triangle ("the Abbey of Hidden Absurdities, where PHP is written")<|eot|><|sol|>http://thecodelesscode.com/case/161<|eol|><|sor|>I, uh, don't get it. Is it about cyclic comparisons?<|eor|><|soopr|>Yeah. "123" < "456A" and "456A" < "78", but "78" < "123".<|eoopr|><|eols|><|endoftext|>
29
lolphp
Rangi42
cke7cla
<|sols|><|sot|>The Codeless Code: Case 161: Triangle ("the Abbey of Hidden Absurdities, where PHP is written")<|eot|><|sol|>http://thecodelesscode.com/case/161<|eol|><|sor|>I, uh, don't get it. Is it about cyclic comparisons?<|eor|><|soopr|>Yeah. "123" < "456A" and "456A" < "78", but "78" < "123".<|eoopr|><|sor|>What happens when you sort those numbers? An infinite loop?<|eor|><|sor|>I don't think so. Technically it depends on the sorting algorithm. I believe PHP uses some variant of quicksort, with the comparison function being php_array_data_compare. I'm not sure if that comparison function has the same property as the < operator in this case. Regardless, I *don't* think PHP's quicksort has a stopping condition which does a pass through the array to "check for sortedness", so no risk of an infinite loop. NB: there *are* some algorithms that attempt to optimize by first checking to see "how sorted" a given array is, since a common case in real systems is a "mostly sorted array"; e.g., 100 already-sorted items plus the 3 that the user just added. <|eor|><|soopr|>I [ran](http://writecodeonline.com/php/) this code in PHP 5: $a = array("123", "456A", "78"); sort($a); print_r($a); $b = array("456A", "78", "123"); sort($b); print_r($b); $c = array("78", "123", "456A"); sort($c); print_r($c); $d = array("78", "456A", "123"); sort($d); print_r($d); And got this output: Array ( [0] => 123 [1] => 456A [2] => 78 ) Array ( [0] => 456A [1] => 78 [2] => 123 ) Array ( [0] => 78 [1] => 123 [2] => 456A ) Array ( [0] => 123 [1] => 456A [2] => 78 ) So if you sort an array, shuffle it, then sort it again, in PHP you're not guaranteed to return the array to its original sorted state.<|eoopr|><|eols|><|endoftext|>
20
lolphp
ajmarks
cke9l44
<|sols|><|sot|>The Codeless Code: Case 161: Triangle ("the Abbey of Hidden Absurdities, where PHP is written")<|eot|><|sol|>http://thecodelesscode.com/case/161<|eol|><|sor|>I, uh, don't get it. Is it about cyclic comparisons?<|eor|><|soopr|>Yeah. "123" < "456A" and "456A" < "78", but "78" < "123".<|eoopr|><|sor|>What happens when you sort those numbers? An infinite loop?<|eor|><|sor|>I don't think so. Technically it depends on the sorting algorithm. I believe PHP uses some variant of quicksort, with the comparison function being php_array_data_compare. I'm not sure if that comparison function has the same property as the < operator in this case. Regardless, I *don't* think PHP's quicksort has a stopping condition which does a pass through the array to "check for sortedness", so no risk of an infinite loop. NB: there *are* some algorithms that attempt to optimize by first checking to see "how sorted" a given array is, since a common case in real systems is a "mostly sorted array"; e.g., 100 already-sorted items plus the 3 that the user just added. <|eor|><|soopr|>I [ran](http://writecodeonline.com/php/) this code in PHP 5: $a = array("123", "456A", "78"); sort($a); print_r($a); $b = array("456A", "78", "123"); sort($b); print_r($b); $c = array("78", "123", "456A"); sort($c); print_r($c); $d = array("78", "456A", "123"); sort($d); print_r($d); And got this output: Array ( [0] => 123 [1] => 456A [2] => 78 ) Array ( [0] => 456A [1] => 78 [2] => 123 ) Array ( [0] => 78 [1] => 123 [2] => 456A ) Array ( [0] => 123 [1] => 456A [2] => 78 ) So if you sort an array, shuffle it, then sort it again, in PHP you're not guaranteed to return the array to its original sorted state.<|eoopr|><|sor|>That is...I don't even have words for it.<|eor|><|eols|><|endoftext|>
14
lolphp
allthediamonds
ckdpj1b
<|sols|><|sot|>The Codeless Code: Case 161: Triangle ("the Abbey of Hidden Absurdities, where PHP is written")<|eot|><|sol|>http://thecodelesscode.com/case/161<|eol|><|sor|>I, uh, don't get it. Is it about cyclic comparisons?<|eor|><|eols|><|endoftext|>
13
lolphp
Rangi42
ckek8an
<|sols|><|sot|>The Codeless Code: Case 161: Triangle ("the Abbey of Hidden Absurdities, where PHP is written")<|eot|><|sol|>http://thecodelesscode.com/case/161<|eol|><|sor|>I, uh, don't get it. Is it about cyclic comparisons?<|eor|><|soopr|>Yeah. "123" < "456A" and "456A" < "78", but "78" < "123".<|eoopr|><|sor|>What happens when you sort those numbers? An infinite loop?<|eor|><|sor|>I don't think so. Technically it depends on the sorting algorithm. I believe PHP uses some variant of quicksort, with the comparison function being php_array_data_compare. I'm not sure if that comparison function has the same property as the < operator in this case. Regardless, I *don't* think PHP's quicksort has a stopping condition which does a pass through the array to "check for sortedness", so no risk of an infinite loop. NB: there *are* some algorithms that attempt to optimize by first checking to see "how sorted" a given array is, since a common case in real systems is a "mostly sorted array"; e.g., 100 already-sorted items plus the 3 that the user just added. <|eor|><|soopr|>I [ran](http://writecodeonline.com/php/) this code in PHP 5: $a = array("123", "456A", "78"); sort($a); print_r($a); $b = array("456A", "78", "123"); sort($b); print_r($b); $c = array("78", "123", "456A"); sort($c); print_r($c); $d = array("78", "456A", "123"); sort($d); print_r($d); And got this output: Array ( [0] => 123 [1] => 456A [2] => 78 ) Array ( [0] => 456A [1] => 78 [2] => 123 ) Array ( [0] => 78 [1] => 123 [2] => 456A ) Array ( [0] => 123 [1] => 456A [2] => 78 ) So if you sort an array, shuffle it, then sort it again, in PHP you're not guaranteed to return the array to its original sorted state.<|eoopr|><|sor|>That is...I don't even have words for it.<|eor|><|soopr|>It gets worse. I was curious what an `is_sorted` function would say about any of those possibilities. The [unanimous](http://stackoverflow.com/questions/14276737/how-to-check-if-an-array-is-already-sorted-in-php) solution of PHP developers is to copy the array, sort the copy, and compare the array with the sorted copy item by item. One justification: "you have multiple sorting algorithms and a computer can't know whether something is sorted unless it tries to sort it and reach the same output as input, making the question kinda - well, silly." Wait, not quite unanimous -- Neil's reasonable suggestion to "use array_reduce to compare each element to the next" has 0 points.<|eoopr|><|eols|><|endoftext|>
12
lolphp
allthediamonds
ckdqhs2
<|sols|><|sot|>The Codeless Code: Case 161: Triangle ("the Abbey of Hidden Absurdities, where PHP is written")<|eot|><|sol|>http://thecodelesscode.com/case/161<|eol|><|sor|>I, uh, don't get it. Is it about cyclic comparisons?<|eor|><|soopr|>Yeah. "123" < "456A" and "456A" < "78", but "78" < "123".<|eoopr|><|sor|>Oh, wow. I thought it had to do something deeper, because I couldn't believe it to be actually true. I knew sorting on PHP was fucked up, but I didn't suspect it was *this* fucked up.<|eor|><|eols|><|endoftext|>
9
lolphp
knaveofspades
ckegdff
<|sols|><|sot|>The Codeless Code: Case 161: Triangle ("the Abbey of Hidden Absurdities, where PHP is written")<|eot|><|sol|>http://thecodelesscode.com/case/161<|eol|><|sor|>I, uh, don't get it. Is it about cyclic comparisons?<|eor|><|soopr|>Yeah. "123" < "456A" and "456A" < "78", but "78" < "123".<|eoopr|><|sor|>Oh, wow. I thought it had to do something deeper, because I couldn't believe it to be actually true. I knew sorting on PHP was fucked up, but I didn't suspect it was *this* fucked up.<|eor|><|sor|>PHP is the only major language where I have been told about a behavior and had to try it for myself because I didn't believe it.<|eor|><|eols|><|endoftext|>
7
lolphp
eryq
cke53ms
<|sols|><|sot|>The Codeless Code: Case 161: Triangle ("the Abbey of Hidden Absurdities, where PHP is written")<|eot|><|sol|>http://thecodelesscode.com/case/161<|eol|><|sor|>I, uh, don't get it. Is it about cyclic comparisons?<|eor|><|soopr|>Yeah. "123" < "456A" and "456A" < "78", but "78" < "123".<|eoopr|><|sor|>What happens when you sort those numbers? An infinite loop?<|eor|><|sor|>I don't think so. Technically it depends on the sorting algorithm. I believe PHP uses some variant of quicksort, with the comparison function being php_array_data_compare. I'm not sure if that comparison function has the same property as the < operator in this case. Regardless, I *don't* think PHP's quicksort has a stopping condition which does a pass through the array to "check for sortedness", so no risk of an infinite loop. NB: there *are* some algorithms that attempt to optimize by first checking to see "how sorted" a given array is, since a common case in real systems is a "mostly sorted array"; e.g., 100 already-sorted items plus the 3 that the user just added. <|eor|><|eols|><|endoftext|>
7
lolphp
Banane9
ckemvwq
<|sols|><|sot|>The Codeless Code: Case 161: Triangle ("the Abbey of Hidden Absurdities, where PHP is written")<|eot|><|sol|>http://thecodelesscode.com/case/161<|eol|><|sor|>I, uh, don't get it. Is it about cyclic comparisons?<|eor|><|soopr|>Yeah. "123" < "456A" and "456A" < "78", but "78" < "123".<|eoopr|><|sor|>Same length as `true == "php" && "php" == 0 && 0 == false`! Truly fairy tale material, with all those triples. I know PHP ~~users~~ weenies will point out that one should use `===`, but I wonder is there something like that for `<` and `>`?<|eor|><|sor|>`<<` and `>>` of course ;)<|eor|><|eols|><|endoftext|>
5
lolphp
jamwaffles
1q41hm
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|eols|><|endoftext|>
36
lolphp
jamwaffles
cd8xlwu
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|soopr|>Why is `$more_entropy` even an argument, and an optional one at that? Surely if you want a unique ID you don't want to have to remember to pass an additional argument that: > ...increases the likelihood that the result will be unique. You want a unique ID every time, unless I'm missing something here...<|eoopr|><|eols|><|endoftext|>
24
lolphp
merreborn
cd94jiw
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|sor|>A couple of gems from the page: > ...in fact without being passed any additional parameters *the return value is little different from microtime()* and > Under Cygwin, the more_entropy must be set to TRUE for this function to work.<|eor|><|eols|><|endoftext|>
20
lolphp
berkes
cd944vn
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|soopr|>Why is `$more_entropy` even an argument, and an optional one at that? Surely if you want a unique ID you don't want to have to remember to pass an additional argument that: > ...increases the likelihood that the result will be unique. You want a unique ID every time, unless I'm missing something here...<|eoopr|><|sor|>Also: apparenty there is unique, non-unique and more-likely-unique. Which is like being somewhat pregnant.<|eor|><|eols|><|endoftext|>
18
lolphp
tdammers
cd96let
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|sor|>Also, the docs make it clear that this is pretty much just some form of MD5(microtime()) Edit: It's not even that. It's just microtime(). Here's the code: gettimeofday((struct timeval *) &tv, (struct timezone *) NULL); sec = (int) tv.tv_sec; usec = (int) (tv.tv_usec % 0x100000); /* The max value usec can have is 0xF423F, so we use only five hex * digits for usecs. */ if (more_entropy) { spprintf(&uniqid, 0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10); } else { spprintf(&uniqid, 0, "%s%08x%05x", prefix, sec, usec); } RETURN_STRING(uniqid, 0);<|eor|><|sor|>Makes sense. The likelyhood of too calls to uniqid being executed in the same microsecond is very low, especially if it's on the same machine.<|eor|><|sor|>Can't tell if sarcasm...<|eor|><|sor|>Why would it be sarcasm? Timestamps are commonly used as part of globally unique ids.<|eor|><|sor|>As *part of*, yes. But the timestamp alone is hardly meaningful on a modern multi-CPU server that can easily process several records in a millisecond; I'd assume that the probability of a collision would be quite high on a busy server.<|eor|><|eols|><|endoftext|>
13
lolphp
ajmarks
cd90p5d
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|sor|>Also, the docs make it clear that this is pretty much just some form of MD5(microtime()) Edit: It's not even that. It's just microtime(). Here's the code: gettimeofday((struct timeval *) &tv, (struct timezone *) NULL); sec = (int) tv.tv_sec; usec = (int) (tv.tv_usec % 0x100000); /* The max value usec can have is 0xF423F, so we use only five hex * digits for usecs. */ if (more_entropy) { spprintf(&uniqid, 0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10); } else { spprintf(&uniqid, 0, "%s%08x%05x", prefix, sec, usec); } RETURN_STRING(uniqid, 0);<|eor|><|eols|><|endoftext|>
12
lolphp
merreborn
cd94p7e
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|soopr|>Why is `$more_entropy` even an argument, and an optional one at that? Surely if you want a unique ID you don't want to have to remember to pass an additional argument that: > ...increases the likelihood that the result will be unique. You want a unique ID every time, unless I'm missing something here...<|eoopr|><|sor|>> Why is $more_entropy even an argument As with a lot of other PHP retardation, the answer is probably backwards compatibility. > [\[The second\] parameter is only available in PHP 4 and PHP 3.0.13 and later.](https://web.archive.org/web/20010605201007/http://www.php.net/manual/en/function.uniqid.php) Older versions of PHP3 had no second argument, and thus always output 13 char strings. Changing the default to 23 chars could break older code. Of course, there are other ways of coping with the backward compatibility issue...<|eor|><|eols|><|endoftext|>
9
lolphp
djsumdog
cd95nbg
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|soopr|>Why is `$more_entropy` even an argument, and an optional one at that? Surely if you want a unique ID you don't want to have to remember to pass an additional argument that: > ...increases the likelihood that the result will be unique. You want a unique ID every time, unless I'm missing something here...<|eoopr|><|sor|>Also: apparenty there is unique, non-unique and more-likely-unique. Which is like being somewhat pregnant.<|eor|><|sor|>It's like when conservatives talk about "rape" vs "real rape" and "legitimate rape" <|eor|><|eols|><|endoftext|>
9
lolphp
Sarcastinator
cd9mhha
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|sor|>The LOL for me is that PHP has all these similar, related yet somehow different functions, with the exact same purpose in totally unrelated names. Like [uniqid](http://php.net/manual/en/function.uniqid.php) here that points to [openssl_random_pseudo_bytes](http://www.php.net/manual/en/function.openssl-random-pseudo-bytes.php) (WTF??), and [htmlspecialchars](http://www.php.net/manual/en/function.htmlspecialchars.php) is similar to, yet different from [htmlentities](http://www.php.net/manual/en/function.htmlentities.php) and [html_entity_encode](http://www.php.net/manual/en/function.html-entity-encode.php). Oh, wait, the latter doesn't exist... but [html_entity_decode](http://www.php.net/manual/en/function.html-entity-decode.php) does. <|eor|><|sor|>They _changed_ the default values for htmlentities in PHP 5.4.0...and then the documentation encourages you to specify them explicitly. edit: Haha! Comments! >Trouble when using files with different charset? > >htmlentities and html_entity_decode can be used to translate between charset! > >Sample function: > > <?php > function utf2latin($text) { > $text=htmlentities($text,ENT_COMPAT,'UTF-8'); > return html_entity_decode($text,ENT_COMPAT,'ISO-8859-1'); > } > ?><|eor|><|eols|><|endoftext|>
7
lolphp
andsens
cd97f43
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|sor|>> more_entropy: If set to TRUE, uniqid() will add additional entropy (**using the combined linear congruential generator**) [..] more_entropy should not be confused with the third (undocumented) parameter [bool $reticulate_splines = false]<|eor|><|eols|><|endoftext|>
6
lolphp
ajmarks
cd95ex8
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|sor|>I find the first argument, $prefix, to be even more puzzling. uniqid($prefix) is *exactly the same thing* as $prefix.uniqid(). There's absolutely no reason for that to be an argument.<|eor|><|eols|><|endoftext|>
6
lolphp
zelenoid
cd99nw5
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|sor|>> more_entropy: If set to TRUE, uniqid() will add additional entropy (**using the combined linear congruential generator**) [..] more_entropy should not be confused with the third (undocumented) parameter [bool $reticulate_splines = false]<|eor|><|sor|>Well it only sounds fancy and secure to those uninformed. In reality, a linear congruential generator is a very old method for a pseudo-random number generator that features high performance but very little else and is certainly not cryptographically secure unless you properly (re)seed it.<|eor|><|eols|><|endoftext|>
6
lolphp
abadidea
cda5pzb
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|sor|>I don't even know what I could say that could add to that manual page. And I run an entire blog that is literally just making fun of the manual <|eor|><|eols|><|endoftext|>
5
lolphp
merreborn
cd94fu7
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|sor|>Also, the docs make it clear that this is pretty much just some form of MD5(microtime()) Edit: It's not even that. It's just microtime(). Here's the code: gettimeofday((struct timeval *) &tv, (struct timezone *) NULL); sec = (int) tv.tv_sec; usec = (int) (tv.tv_usec % 0x100000); /* The max value usec can have is 0xF423F, so we use only five hex * digits for usecs. */ if (more_entropy) { spprintf(&uniqid, 0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10); } else { spprintf(&uniqid, 0, "%s%08x%05x", prefix, sec, usec); } RETURN_STRING(uniqid, 0);<|eor|><|sor|>Stumbled on some pretty detailed analysis of that code here: http://seclists.org/fulldisclosure/2010/Mar/519<|eor|><|eols|><|endoftext|>
5
lolphp
DroolingIguana
cdwyevk
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|soopr|>Why is `$more_entropy` even an argument, and an optional one at that? Surely if you want a unique ID you don't want to have to remember to pass an additional argument that: > ...increases the likelihood that the result will be unique. You want a unique ID every time, unless I'm missing something here...<|eoopr|><|sor|>> Why is $more_entropy even an argument As with a lot of other PHP retardation, the answer is probably backwards compatibility. > [\[The second\] parameter is only available in PHP 4 and PHP 3.0.13 and later.](https://web.archive.org/web/20010605201007/http://www.php.net/manual/en/function.uniqid.php) Older versions of PHP3 had no second argument, and thus always output 13 char strings. Changing the default to 23 chars could break older code. Of course, there are other ways of coping with the backward compatibility issue...<|eor|><|sor|>> Of course, there are other ways of coping with the backward compatibility issue... example? How would you solve this particular problem if you don't want to be laughed at by the community? Or yelled at by some people whose application you just broke because your unique ids changed their format? <|eor|><|sor|>Make a new function with a new name. Deprecate the old one and throw out warnings whenever it's used.<|eor|><|eols|><|endoftext|>
5
lolphp
pilif
cdx8k91
<|sols|><|sot|>Entropy is not enough. We need MORE.<|eot|><|sol|>http://php.net/manual/en/function.uniqid.php<|eol|><|soopr|>Why is `$more_entropy` even an argument, and an optional one at that? Surely if you want a unique ID you don't want to have to remember to pass an additional argument that: > ...increases the likelihood that the result will be unique. You want a unique ID every time, unless I'm missing something here...<|eoopr|><|sor|>> Why is $more_entropy even an argument As with a lot of other PHP retardation, the answer is probably backwards compatibility. > [\[The second\] parameter is only available in PHP 4 and PHP 3.0.13 and later.](https://web.archive.org/web/20010605201007/http://www.php.net/manual/en/function.uniqid.php) Older versions of PHP3 had no second argument, and thus always output 13 char strings. Changing the default to 23 chars could break older code. Of course, there are other ways of coping with the backward compatibility issue...<|eor|><|sor|>> Of course, there are other ways of coping with the backward compatibility issue... example? How would you solve this particular problem if you don't want to be laughed at by the community? Or yelled at by some people whose application you just broke because your unique ids changed their format? <|eor|><|sor|>Make a new function with a new name. Deprecate the old one and throw out warnings whenever it's used.<|eor|><|sor|>That's how we got mysql_real_escape_string() which is another one of these things everybody is complaining about<|eor|><|eols|><|endoftext|>
5
lolphp
midir
1n1sjr
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|eoss|><|endoftext|>
36
lolphp
BufferUnderpants
ccemsq6
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>Well, it's undefined behavior *for a reason*. The reason being that its actual behavior has no reason.<|eor|><|eoss|><|endoftext|>
26
lolphp
merreborn
ccesm2o
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>Well, it's undefined behavior *for a reason*. The reason being that its actual behavior has no reason.<|eor|><|sor|>This seems like a good example of GIGO. Shit code in, unpredictable output out. This would be shit code in just about any C-like language. Not just PHP.<|eor|><|eoss|><|endoftext|>
22
lolphp
tudborg
cceog9h
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>What you are seeing is ($a+$a)+$a++ And $a+$a++ If you think of $a++ as a function with the side effect of incrementing a by one and returning the value before the increment, it might be easier to understand why this is happening. function incr_a () {global $a; $b = $a; $a += 1; return $b;} In your first example you are doing (1+1)+incr_a() == 3 and in your second example 2+incr_a() == 3 So both results == 3. This might look funky, but it is actually expected. See http://php.net/manual/en/language.operators.precedence.php<|eor|><|eoss|><|endoftext|>
17
lolphp
BufferUnderpants
ccen9vx
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>Well, it's undefined behavior *for a reason*. The reason being that its actual behavior has no reason.<|eor|><|sor|>What is undefined here? <|eor|><|sor|>Son of a gun, you're right! The manual [guarantees that ``$a++`` will evaluate to ``$a`` prior to incrementing](http://www.php.net/manual/en/language.operators.increment.php). It must be the operator precedence, then? The documentation would be incorrect in that case (inconceivable!), as it states that [``++`` has higher precedence than ``+``](http://php.net/manual/en/language.operators.precedence.php), so it should get executed first than the rest, but it's probably doing ``($a + $a) + $a++`` in the first example. Which is probably because these guys couldn't write a parser to save their lives.<|eor|><|eoss|><|endoftext|>
16
lolphp
nikic
cces5h2
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>Well, it's undefined behavior *for a reason*. The reason being that its actual behavior has no reason.<|eor|><|sor|>What is undefined here? <|eor|><|sor|>Son of a gun, you're right! The manual [guarantees that ``$a++`` will evaluate to ``$a`` prior to incrementing](http://www.php.net/manual/en/language.operators.increment.php). It must be the operator precedence, then? The documentation would be incorrect in that case (inconceivable!), as it states that [``++`` has higher precedence than ``+``](http://php.net/manual/en/language.operators.precedence.php), so it should get executed first than the rest, but it's probably doing ``($a + $a) + $a++`` in the first example. Which is probably because these guys couldn't write a parser to save their lives.<|eor|><|sor|>Operator precedence has *nothing* to do with evaluation order. Precedence tells you that `$a + $b * $c` is grouped as `$a + ($b * $c)` but it does not tell you whether `$a` or `$b * $c` should be evaluated first. And before you ask, no, associativity doesn't have anything to do with this either. Assigning a variable and reading it in the same expression is undefined behavior in most languages - including PHP. <|eor|><|eoss|><|endoftext|>
14
lolphp
HaMMeReD
ccemzpl
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>Well, it's undefined behavior *for a reason*. The reason being that its actual behavior has no reason.<|eor|><|sor|>What is undefined here? <|eor|><|eoss|><|endoftext|>
13
lolphp
nikic
ccesb07
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>What you are seeing is ($a+$a)+$a++ And $a+$a++ If you think of $a++ as a function with the side effect of incrementing a by one and returning the value before the increment, it might be easier to understand why this is happening. function incr_a () {global $a; $b = $a; $a += 1; return $b;} In your first example you are doing (1+1)+incr_a() == 3 and in your second example 2+incr_a() == 3 So both results == 3. This might look funky, but it is actually expected. See http://php.net/manual/en/language.operators.precedence.php<|eor|><|sor|>why is the 2nd example 2+incr_a()? right before he declares $a = 1. just to make my sure I was looking at this correctly i programmed it quickly in c. #include <stdio.h> int main() { int a = 1; int b = a + a + a++; printf("a %d, b %d\n",a,b); a = 1; b = a + a++; printf("a %d, b %d\n",a,b); } which yields a 2, b 3 a 2, b 2 I also verified the OP results which obviously not the same as my c version what am i missing? <|eor|><|sor|>The result you got in C is purely incidental. Your program invokes [undefined behavior](http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points), as such the compiler can produce whichever output it likes. PHP has two times the same output because in the first case it executes `($a + $a)` first and `$a++` afterwards, but in the second case runs `$a++` first and `$a` afterwards. This has to do with CV optimizations in the VM.<|eor|><|eoss|><|endoftext|>
10
lolphp
djsumdog
ccey5d4
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>Well, it's undefined behavior *for a reason*. The reason being that its actual behavior has no reason.<|eor|><|sor|>This seems like a good example of GIGO. Shit code in, unpredictable output out. This would be shit code in just about any C-like language. Not just PHP.<|eor|><|sor|>It's one of those basic rules that you should never assign and modify a scalar in the same statement. <|eor|><|eoss|><|endoftext|>
9
lolphp
infinull
ccep71h
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>What you are seeing is ($a+$a)+$a++ And $a+$a++ If you think of $a++ as a function with the side effect of incrementing a by one and returning the value before the increment, it might be easier to understand why this is happening. function incr_a () {global $a; $b = $a; $a += 1; return $b;} In your first example you are doing (1+1)+incr_a() == 3 and in your second example 2+incr_a() == 3 So both results == 3. This might look funky, but it is actually expected. See http://php.net/manual/en/language.operators.precedence.php<|eor|><|sor|>This is one of the reasons why python dropped doesn't let assignment operators return values.<|eor|><|eoss|><|endoftext|>
7
lolphp
niiko
ccet710
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>What you are seeing is ($a+$a)+$a++ And $a+$a++ If you think of $a++ as a function with the side effect of incrementing a by one and returning the value before the increment, it might be easier to understand why this is happening. function incr_a () {global $a; $b = $a; $a += 1; return $b;} In your first example you are doing (1+1)+incr_a() == 3 and in your second example 2+incr_a() == 3 So both results == 3. This might look funky, but it is actually expected. See http://php.net/manual/en/language.operators.precedence.php<|eor|><|sor|>Could you explain how you're getting the 2 in 2+incr_a() == 3 ? Did you miss that the preceding statement sets $a back to one? Out of curiosity I extended the example: $a = 1; $c = $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a + $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a + $a + $a + $a + $a++; var_dump($c); int(1) int(3) int(3) int(4) int(5) int(6) nikic mentions its undefined behaviour, and I could accept that, but you're saying its *expected*. I'd just like some clarification if you know what's happening.<|eor|><|eoss|><|endoftext|>
7
lolphp
sbditto85
ccer6r6
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>What you are seeing is ($a+$a)+$a++ And $a+$a++ If you think of $a++ as a function with the side effect of incrementing a by one and returning the value before the increment, it might be easier to understand why this is happening. function incr_a () {global $a; $b = $a; $a += 1; return $b;} In your first example you are doing (1+1)+incr_a() == 3 and in your second example 2+incr_a() == 3 So both results == 3. This might look funky, but it is actually expected. See http://php.net/manual/en/language.operators.precedence.php<|eor|><|sor|>why is the 2nd example 2+incr_a()? right before he declares $a = 1. just to make my sure I was looking at this correctly i programmed it quickly in c. #include <stdio.h> int main() { int a = 1; int b = a + a + a++; printf("a %d, b %d\n",a,b); a = 1; b = a + a++; printf("a %d, b %d\n",a,b); } which yields a 2, b 3 a 2, b 2 I also verified the OP results which obviously not the same as my c version what am i missing? <|eor|><|eoss|><|endoftext|>
7
lolphp
Sarcastinator
ccexhnq
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>Well, it's undefined behavior *for a reason*. The reason being that its actual behavior has no reason.<|eor|><|sor|>What is undefined here? <|eor|><|sor|>Son of a gun, you're right! The manual [guarantees that ``$a++`` will evaluate to ``$a`` prior to incrementing](http://www.php.net/manual/en/language.operators.increment.php). It must be the operator precedence, then? The documentation would be incorrect in that case (inconceivable!), as it states that [``++`` has higher precedence than ``+``](http://php.net/manual/en/language.operators.precedence.php), so it should get executed first than the rest, but it's probably doing ``($a + $a) + $a++`` in the first example. Which is probably because these guys couldn't write a parser to save their lives.<|eor|><|sor|>Operator precedence has *nothing* to do with evaluation order. Precedence tells you that `$a + $b * $c` is grouped as `$a + ($b * $c)` but it does not tell you whether `$a` or `$b * $c` should be evaluated first. And before you ask, no, associativity doesn't have anything to do with this either. Assigning a variable and reading it in the same expression is undefined behavior in most languages - including PHP. <|eor|><|sor|>> Assigning a variable and reading it in the same expression is undefined behavior in most languages - including PHP. False. It is undefined in C, C++ ~~and PHP~~. Not Java, C# or Python. Perhaps it is undefined in Perl as well, I don't know, but there certainly is no reason for PHP to omit this.<|eor|><|eoss|><|endoftext|>
7
lolphp
tudborg
ccepa4q
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>What you are seeing is ($a+$a)+$a++ And $a+$a++ If you think of $a++ as a function with the side effect of incrementing a by one and returning the value before the increment, it might be easier to understand why this is happening. function incr_a () {global $a; $b = $a; $a += 1; return $b;} In your first example you are doing (1+1)+incr_a() == 3 and in your second example 2+incr_a() == 3 So both results == 3. This might look funky, but it is actually expected. See http://php.net/manual/en/language.operators.precedence.php<|eor|><|sor|>This is one of the reasons why python dropped doesn't let assignment operators return values.<|eor|><|sor|>And it was a good decision. It just confuses people. <|eor|><|eoss|><|endoftext|>
6
lolphp
merreborn
ccesk11
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>What you are seeing is ($a+$a)+$a++ And $a+$a++ If you think of $a++ as a function with the side effect of incrementing a by one and returning the value before the increment, it might be easier to understand why this is happening. function incr_a () {global $a; $b = $a; $a += 1; return $b;} In your first example you are doing (1+1)+incr_a() == 3 and in your second example 2+incr_a() == 3 So both results == 3. This might look funky, but it is actually expected. See http://php.net/manual/en/language.operators.precedence.php<|eor|><|sor|>why is the 2nd example 2+incr_a()? right before he declares $a = 1. just to make my sure I was looking at this correctly i programmed it quickly in c. #include <stdio.h> int main() { int a = 1; int b = a + a + a++; printf("a %d, b %d\n",a,b); a = 1; b = a + a++; printf("a %d, b %d\n",a,b); } which yields a 2, b 3 a 2, b 2 I also verified the OP results which obviously not the same as my c version what am i missing? <|eor|><|sor|>The result you got in C is purely incidental. Your program invokes [undefined behavior](http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points), as such the compiler can produce whichever output it likes. PHP has two times the same output because in the first case it executes `($a + $a)` first and `$a++` afterwards, but in the second case runs `$a++` first and `$a` afterwards. This has to do with CV optimizations in the VM.<|eor|><|sor|>> CV optimization I'm not familiar with this acronym. What is CV? Constant Value?<|eor|><|eoss|><|endoftext|>
5
lolphp
BufferUnderpants
ccetrgp
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>Well, it's undefined behavior *for a reason*. The reason being that its actual behavior has no reason.<|eor|><|sor|>What is undefined here? <|eor|><|sor|>Son of a gun, you're right! The manual [guarantees that ``$a++`` will evaluate to ``$a`` prior to incrementing](http://www.php.net/manual/en/language.operators.increment.php). It must be the operator precedence, then? The documentation would be incorrect in that case (inconceivable!), as it states that [``++`` has higher precedence than ``+``](http://php.net/manual/en/language.operators.precedence.php), so it should get executed first than the rest, but it's probably doing ``($a + $a) + $a++`` in the first example. Which is probably because these guys couldn't write a parser to save their lives.<|eor|><|sor|>Operator precedence has *nothing* to do with evaluation order. Precedence tells you that `$a + $b * $c` is grouped as `$a + ($b * $c)` but it does not tell you whether `$a` or `$b * $c` should be evaluated first. And before you ask, no, associativity doesn't have anything to do with this either. Assigning a variable and reading it in the same expression is undefined behavior in most languages - including PHP. <|eor|><|sor|>But the documentation *does* state an order of evaluation. I know that most languages don't make any guarantees in respect to that, and especially in this corner case (and I personally think that the operator is just superfluous syntactic sugar in all languages), which was my hunch, but unless I'm seriously misreading this, these guys are putting the rope on their own necks.<|eor|><|eoss|><|endoftext|>
5
lolphp
nikic
ccf2qdg
<|soss|><|sot|>PHP just does what it wants<|eot|><|sost|> $a = 1; $c = $a + $a + $a++; var_dump($c); $a = 1; $c = $a + $a++; var_dump($c); The incredible output of this is: int(3) int(3) <|eost|><|sor|>What you are seeing is ($a+$a)+$a++ And $a+$a++ If you think of $a++ as a function with the side effect of incrementing a by one and returning the value before the increment, it might be easier to understand why this is happening. function incr_a () {global $a; $b = $a; $a += 1; return $b;} In your first example you are doing (1+1)+incr_a() == 3 and in your second example 2+incr_a() == 3 So both results == 3. This might look funky, but it is actually expected. See http://php.net/manual/en/language.operators.precedence.php<|eor|><|sor|>why is the 2nd example 2+incr_a()? right before he declares $a = 1. just to make my sure I was looking at this correctly i programmed it quickly in c. #include <stdio.h> int main() { int a = 1; int b = a + a + a++; printf("a %d, b %d\n",a,b); a = 1; b = a + a++; printf("a %d, b %d\n",a,b); } which yields a 2, b 3 a 2, b 2 I also verified the OP results which obviously not the same as my c version what am i missing? <|eor|><|sor|>The result you got in C is purely incidental. Your program invokes [undefined behavior](http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points), as such the compiler can produce whichever output it likes. PHP has two times the same output because in the first case it executes `($a + $a)` first and `$a++` afterwards, but in the second case runs `$a++` first and `$a` afterwards. This has to do with CV optimizations in the VM.<|eor|><|sor|>> CV optimization I'm not familiar with this acronym. What is CV? Constant Value?<|eor|><|sor|>Compiled variables optimization. I quickly wrote up a gist explaining it: https://gist.github.com/nikic/6699370<|eor|><|eoss|><|endoftext|>
5
lolphp
jamwaffles
1jua0l
<|soss|><|sot|>Function names are case insensitive. Even the built in ones<|eot|><|sost|>This made me WTF quite hard. I was browsing StackOverflow and came across [this question](http://stackoverflow.com/questions/18091130/how-can-i-optimize-image-resize-code) showing that **even built in functions aren't case sensitive** which led me to [this answer](http://stackoverflow.com/a/6302488/383609). To copy the quoted quote (hnnng): > The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library. >The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C. This makes sense... if you're writing a fucking HTML parser.<|eost|><|eoss|><|endoftext|>
36
lolphp
Rhomboid
cbicvok
<|soss|><|sot|>Function names are case insensitive. Even the built in ones<|eot|><|sost|>This made me WTF quite hard. I was browsing StackOverflow and came across [this question](http://stackoverflow.com/questions/18091130/how-can-i-optimize-image-resize-code) showing that **even built in functions aren't case sensitive** which led me to [this answer](http://stackoverflow.com/a/6302488/383609). To copy the quoted quote (hnnng): > The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library. >The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C. This makes sense... if you're writing a fucking HTML parser.<|eost|><|sor|>Oh it's far more insane that that. [Some things are case sensitive, some are case-insensitive](http://the-echoplex.net/log/php-case-sensitivity): class Foo { const Bar = 42; function showBar() { echo self::Bar, "\n"; } } $baz = new FOO(); $baz->SHOWBAR(); // OK echo FOO::Bar, "\n"; // OK echo FOO::BAR, "\n"; // PHP Fatal error: Undefined class constant 'BAR' in ... <|eor|><|eoss|><|endoftext|>
29
lolphp
Sgeo
cbidcdm
<|soss|><|sot|>Function names are case insensitive. Even the built in ones<|eot|><|sost|>This made me WTF quite hard. I was browsing StackOverflow and came across [this question](http://stackoverflow.com/questions/18091130/how-can-i-optimize-image-resize-code) showing that **even built in functions aren't case sensitive** which led me to [this answer](http://stackoverflow.com/a/6302488/383609). To copy the quoted quote (hnnng): > The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library. >The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C. This makes sense... if you're writing a fucking HTML parser.<|eost|><|sor|>Oh it's far more insane that that. [Some things are case sensitive, some are case-insensitive](http://the-echoplex.net/log/php-case-sensitivity): class Foo { const Bar = 42; function showBar() { echo self::Bar, "\n"; } } $baz = new FOO(); $baz->SHOWBAR(); // OK echo FOO::Bar, "\n"; // OK echo FOO::BAR, "\n"; // PHP Fatal error: Undefined class constant 'BAR' in ... <|eor|><|sor|>It's this bizarre mixture of case sensitivity and case insensitivity that bothers me far more than mere case insensitivity. Nothing wrong with case insensitivity in and of itself.<|eor|><|eoss|><|endoftext|>
25
lolphp
redalastor
cbiee6f
<|soss|><|sot|>Function names are case insensitive. Even the built in ones<|eot|><|sost|>This made me WTF quite hard. I was browsing StackOverflow and came across [this question](http://stackoverflow.com/questions/18091130/how-can-i-optimize-image-resize-code) showing that **even built in functions aren't case sensitive** which led me to [this answer](http://stackoverflow.com/a/6302488/383609). To copy the quoted quote (hnnng): > The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library. >The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C. This makes sense... if you're writing a fucking HTML parser.<|eost|><|sor|>Oh it's far more insane that that. [Some things are case sensitive, some are case-insensitive](http://the-echoplex.net/log/php-case-sensitivity): class Foo { const Bar = 42; function showBar() { echo self::Bar, "\n"; } } $baz = new FOO(); $baz->SHOWBAR(); // OK echo FOO::Bar, "\n"; // OK echo FOO::BAR, "\n"; // PHP Fatal error: Undefined class constant 'BAR' in ... <|eor|><|sor|>It's this bizarre mixture of case sensitivity and case insensitivity that bothers me far more than mere case insensitivity. Nothing wrong with case insensitivity in and of itself.<|eor|><|sor|>There's even a good argument for it since it's bad style to have two variables where the only difference is the case.<|eor|><|eoss|><|endoftext|>
10
lolphp
philsturgeon
cbrisgj
<|soss|><|sot|>Function names are case insensitive. Even the built in ones<|eot|><|sost|>This made me WTF quite hard. I was browsing StackOverflow and came across [this question](http://stackoverflow.com/questions/18091130/how-can-i-optimize-image-resize-code) showing that **even built in functions aren't case sensitive** which led me to [this answer](http://stackoverflow.com/a/6302488/383609). To copy the quoted quote (hnnng): > The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library. >The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C. This makes sense... if you're writing a fucking HTML parser.<|eost|><|sor|>> "if you rely on case sensitivity to recognize one function name from another, you're in kind of serious trouble!" -- Rasmus Lerdorf Fair.<|eor|><|eoss|><|endoftext|>
9
lolphp
midir
cbiqjvn
<|soss|><|sot|>Function names are case insensitive. Even the built in ones<|eot|><|sost|>This made me WTF quite hard. I was browsing StackOverflow and came across [this question](http://stackoverflow.com/questions/18091130/how-can-i-optimize-image-resize-code) showing that **even built in functions aren't case sensitive** which led me to [this answer](http://stackoverflow.com/a/6302488/383609). To copy the quoted quote (hnnng): > The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library. >The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C. This makes sense... if you're writing a fucking HTML parser.<|eost|><|sor|>https://pay.reddit.com/r/lolphp/comments/y7dun/the_php_way_variables_are_casesensitive_but/ >case-sensitive names are actually locale-sensitive.<|eor|><|eoss|><|endoftext|>
9
lolphp
michaelpb
cbitjur
<|soss|><|sot|>Function names are case insensitive. Even the built in ones<|eot|><|sost|>This made me WTF quite hard. I was browsing StackOverflow and came across [this question](http://stackoverflow.com/questions/18091130/how-can-i-optimize-image-resize-code) showing that **even built in functions aren't case sensitive** which led me to [this answer](http://stackoverflow.com/a/6302488/383609). To copy the quoted quote (hnnng): > The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library. >The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C. This makes sense... if you're writing a fucking HTML parser.<|eost|><|sor|>Oh it's far more insane that that. [Some things are case sensitive, some are case-insensitive](http://the-echoplex.net/log/php-case-sensitivity): class Foo { const Bar = 42; function showBar() { echo self::Bar, "\n"; } } $baz = new FOO(); $baz->SHOWBAR(); // OK echo FOO::Bar, "\n"; // OK echo FOO::BAR, "\n"; // PHP Fatal error: Undefined class constant 'BAR' in ... <|eor|><|sor|>It's this bizarre mixture of case sensitivity and case insensitivity that bothers me far more than mere case insensitivity. Nothing wrong with case insensitivity in and of itself.<|eor|><|sor|>There's even a good argument for it since it's bad style to have two variables where the only difference is the case.<|eor|><|sor|>well perhaps for php / perl, but in languages where functions / classes are first class citizens and sigils aren't used as in php / perl, this is impossible. For example in python you might have: class Hovercraft: # snip hovercraft = Hovercraft() if "eels" in hovercraft: pass <|eor|><|eoss|><|endoftext|>
7
lolphp
TheCoelacanth
cbig0v4
<|soss|><|sot|>Function names are case insensitive. Even the built in ones<|eot|><|sost|>This made me WTF quite hard. I was browsing StackOverflow and came across [this question](http://stackoverflow.com/questions/18091130/how-can-i-optimize-image-resize-code) showing that **even built in functions aren't case sensitive** which led me to [this answer](http://stackoverflow.com/a/6302488/383609). To copy the quoted quote (hnnng): > The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library. >The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C. This makes sense... if you're writing a fucking HTML parser.<|eost|><|sor|>Oh it's far more insane that that. [Some things are case sensitive, some are case-insensitive](http://the-echoplex.net/log/php-case-sensitivity): class Foo { const Bar = 42; function showBar() { echo self::Bar, "\n"; } } $baz = new FOO(); $baz->SHOWBAR(); // OK echo FOO::Bar, "\n"; // OK echo FOO::BAR, "\n"; // PHP Fatal error: Undefined class constant 'BAR' in ... <|eor|><|sor|>It's this bizarre mixture of case sensitivity and case insensitivity that bothers me far more than mere case insensitivity. Nothing wrong with case insensitivity in and of itself.<|eor|><|sor|>There's even a good argument for it since it's bad style to have two variables where the only difference is the case.<|eor|><|sor|>On the other hand, it's also bad style to use inconsistent case in variable names, so what's probably best is case sensitivity, but rejecting variable names that differ only by case.<|eor|><|eoss|><|endoftext|>
7
lolphp
redalastor
cbiko1b
<|soss|><|sot|>Function names are case insensitive. Even the built in ones<|eot|><|sost|>This made me WTF quite hard. I was browsing StackOverflow and came across [this question](http://stackoverflow.com/questions/18091130/how-can-i-optimize-image-resize-code) showing that **even built in functions aren't case sensitive** which led me to [this answer](http://stackoverflow.com/a/6302488/383609). To copy the quoted quote (hnnng): > The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library. >The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C. This makes sense... if you're writing a fucking HTML parser.<|eost|><|sor|>Oh it's far more insane that that. [Some things are case sensitive, some are case-insensitive](http://the-echoplex.net/log/php-case-sensitivity): class Foo { const Bar = 42; function showBar() { echo self::Bar, "\n"; } } $baz = new FOO(); $baz->SHOWBAR(); // OK echo FOO::Bar, "\n"; // OK echo FOO::BAR, "\n"; // PHP Fatal error: Undefined class constant 'BAR' in ... <|eor|><|sor|>It's this bizarre mixture of case sensitivity and case insensitivity that bothers me far more than mere case insensitivity. Nothing wrong with case insensitivity in and of itself.<|eor|><|sor|>There's even a good argument for it since it's bad style to have two variables where the only difference is the case.<|eor|><|sor|>On the other hand, it's also bad style to use inconsistent case in variable names, so what's probably best is case sensitivity, but rejecting variable names that differ only by case.<|eor|><|sor|>In the same file / project / library, absolutely. But if different people want to use the same libraries and use different conventions, I think it's a minor sin to ignore case (and even underscores). It's better to have strong conventions like Python where there's one true way to case your variables but in some communities, order cannot be imposed.<|eor|><|eoss|><|endoftext|>
5
lolphp
Elite6809
cbmfuj7
<|soss|><|sot|>Function names are case insensitive. Even the built in ones<|eot|><|sost|>This made me WTF quite hard. I was browsing StackOverflow and came across [this question](http://stackoverflow.com/questions/18091130/how-can-i-optimize-image-resize-code) showing that **even built in functions aren't case sensitive** which led me to [this answer](http://stackoverflow.com/a/6302488/383609). To copy the quoted quote (hnnng): > The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library. >The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C. This makes sense... if you're writing a fucking HTML parser.<|eost|><|sor|>Oh it's far more insane that that. [Some things are case sensitive, some are case-insensitive](http://the-echoplex.net/log/php-case-sensitivity): class Foo { const Bar = 42; function showBar() { echo self::Bar, "\n"; } } $baz = new FOO(); $baz->SHOWBAR(); // OK echo FOO::Bar, "\n"; // OK echo FOO::BAR, "\n"; // PHP Fatal error: Undefined class constant 'BAR' in ... <|eor|><|sor|>It's this bizarre mixture of case sensitivity and case insensitivity that bothers me far more than mere case insensitivity. Nothing wrong with case insensitivity in and of itself.<|eor|><|sor|>There's even a good argument for it since it's bad style to have two variables where the only difference is the case.<|eor|><|sor|>On the other hand, it's also bad style to use inconsistent case in variable names, so what's probably best is case sensitivity, but rejecting variable names that differ only by case.<|eor|><|sor|>In the same file / project / library, absolutely. But if different people want to use the same libraries and use different conventions, I think it's a minor sin to ignore case (and even underscores). It's better to have strong conventions like Python where there's one true way to case your variables but in some communities, order cannot be imposed.<|eor|><|sor|>> in some communities, order cannot be imposed. $pEnGuIn_Of_dOoM = new PeNgUiN_oF_DoOm(); // I'm so random xDDDD<|eor|><|sor|>You monster.<|eor|><|eoss|><|endoftext|>
5
lolphp
postmodest
1fvp0n
<|soss|><|sot|>DateTime::add "Returns the DateTime object for method chaining or FALSE on failure."<|eot|><|sost|>WAT. And you can't get out of that with a try { } catch () {} because it's a fatal error. You're not even trying, guys. Seriously. <|eost|><|eoss|><|endoftext|>
39
lolphp
throwaway-o
caevuin
<|soss|><|sot|>DateTime::add "Returns the DateTime object for method chaining or FALSE on failure."<|eot|><|sost|>WAT. And you can't get out of that with a try { } catch () {} because it's a fatal error. You're not even trying, guys. Seriously. <|eost|><|sor|>PHP: "I see your method chaining and I raise you a cruel sabotage."<|eor|><|eoss|><|endoftext|>
21
lolphp
postmodest
caefkgu
<|soss|><|sot|>DateTime::add "Returns the DateTime object for method chaining or FALSE on failure."<|eot|><|sost|>WAT. And you can't get out of that with a try { } catch () {} because it's a fatal error. You're not even trying, guys. Seriously. <|eost|><|sor|>I'm idly beginning to wonder how difficult it would be to reimplement PHP to actually be clean. <|eor|><|soopr|>\#!/usr/bin/perl You're welcome. <|eoopr|><|eoss|><|endoftext|>
20
lolphp
rossryan
caee2s6
<|soss|><|sot|>DateTime::add "Returns the DateTime object for method chaining or FALSE on failure."<|eot|><|sost|>WAT. And you can't get out of that with a try { } catch () {} because it's a fatal error. You're not even trying, guys. Seriously. <|eost|><|sor|>I'm idly beginning to wonder how difficult it would be to reimplement PHP to actually be clean. <|eor|><|eoss|><|endoftext|>
13
lolphp
Drainedsoul
caeltx5
<|soss|><|sot|>DateTime::add "Returns the DateTime object for method chaining or FALSE on failure."<|eot|><|sost|>WAT. And you can't get out of that with a try { } catch () {} because it's a fatal error. You're not even trying, guys. Seriously. <|eost|><|sor|>I'm idly beginning to wonder how difficult it would be to reimplement PHP to actually be clean. <|eor|><|sor|>Sometimes I think about how great it'd be to be able to write C++ with <?cpp and ?>. It'd be like writing PHP except without the fucking awful type system and with a class system that actually made sense. I mean it's not like you'd lose any functionality, the C standard library, cURL, OpenSSL, etc. that PHP oh-so-thinly wraps would still be there!<|eor|><|eoss|><|endoftext|>
10
lolphp
postmodest
caj9yui
<|soss|><|sot|>DateTime::add "Returns the DateTime object for method chaining or FALSE on failure."<|eot|><|sost|>WAT. And you can't get out of that with a try { } catch () {} because it's a fatal error. You're not even trying, guys. Seriously. <|eost|><|sor|>What PHP version are you running? With PHP5.4, you can catch the exception thrown by the DateInterval constructor. I haven't tested 5.3 yet... $d = new DateTime(); try { echo $d->add(new DateInterval("x"))->format("Y"); } catch (Exception $e) { echo $e->getMessage(); // "DateInterval::__construct(): Unknown or bad format (x)" } If you don't at least try to provide a `DateInterval` object to the `add` parameter as required and still use method chaining, yes it will cause a fatal "call to member function on non-object" error. Allowing for method chaining can be a bit tricky regardless. Like the top comment on the manual page said two years ago: > Note that the add() and sub() methods will modify the value of the object you're calling the method on! $d = new DateTime(); $newD = $d->add(new DateInterval("P1Y")); echo $d->format("Y"); // 2014 <|eor|><|soopr|>That's catchable, but that's not what I'm talking about (and chaining from a constructor doesn't work in 5.3). What I'm talking about is $d = new DateTime(); $d->add("balls")->add(new DateInterval()); the first call to ->add returns false so you CANNOT USE IT FOR METHOD CHAINING. and in addition, it is a fatal error and won't get caught. Yay. <|eoopr|><|eoss|><|endoftext|>
7
lolphp
huf
caeq9p3
<|soss|><|sot|>DateTime::add "Returns the DateTime object for method chaining or FALSE on failure."<|eot|><|sost|>WAT. And you can't get out of that with a try { } catch () {} because it's a fatal error. You're not even trying, guys. Seriously. <|eost|><|sor|>I'm idly beginning to wonder how difficult it would be to reimplement PHP to actually be clean. <|eor|><|soopr|>\#!/usr/bin/perl You're welcome. <|eoopr|><|sor|>yeap. to fix php, you'd basically have to do what strict.pm and warnings.pm did for perl. it's been done before, both the mistakes and the way forward. still no use-case for php :D<|eor|><|eoss|><|endoftext|>
5
lolphp
Takeoded
iqlpur
<|sols|><|sot|>set_exception_handler() returns NULL on error, and sometimes NULL on success, makes you wonder "why did it return null?"<|eot|><|sol|>https://www.php.net/manual/en/function.set-exception-handler.php<|eol|><|eols|><|endoftext|>
35
lolphp
Takeoded
g4swd8w
<|sols|><|sot|>set_exception_handler() returns NULL on error, and sometimes NULL on success, makes you wonder "why did it return null?"<|eot|><|sol|>https://www.php.net/manual/en/function.set-exception-handler.php<|eol|><|soopr|>.. also makes me wonder, "why doesn't it return bool(false) on error", like everything else in PHP does on error? it could easily be "NULL: no previous handler. false: error. callable: previous hanndler", but no, i guess that would be too much consistency<|eoopr|><|eols|><|endoftext|>
23
lolphp
Almamu
g4vskxv
<|sols|><|sot|>set_exception_handler() returns NULL on error, and sometimes NULL on success, makes you wonder "why did it return null?"<|eot|><|sol|>https://www.php.net/manual/en/function.set-exception-handler.php<|eol|><|sor|>At least it doesn't try to throw an exception upon failure to set an exception handler...?<|eor|><|sor|>That's more sensible than relying on the return value of the function IMO (at least as it is right now). You can catch that and act accordingly fully knowing that the new exception handler wasn't set.<|eor|><|eols|><|endoftext|>
6
lolphp
Takeoded
g4vqawh
<|sols|><|sot|>set_exception_handler() returns NULL on error, and sometimes NULL on success, makes you wonder "why did it return null?"<|eot|><|sol|>https://www.php.net/manual/en/function.set-exception-handler.php<|eol|><|sor|>At least it doesn't try to throw an exception upon failure to set an exception handler...?<|eor|><|soopr|>That's what php8 does apparently, not sure if that's better or worse<|eoopr|><|eols|><|endoftext|>
5
lolphp
girst
agam6a
<|sols|><|sot|>PHPs fopen() is broken (2017)<|eot|><|sol|>https://arp242.net/weblog/php-fopen-is-broken.html<|eol|><|eols|><|endoftext|>
39
lolphp
innerspirit
ee4scly
<|sols|><|sot|>PHPs fopen() is broken (2017)<|eot|><|sol|>https://arp242.net/weblog/php-fopen-is-broken.html<|eol|><|soopr|>It's been years since I've last touched PHP. Does anyone know if these 7.0 weaknesses were adressed in 7.1 or .2?<|eoopr|><|sor|>I'm not sure that they are going to convert that kind of warning into throwables any time soon, seeing as how that would break pretty much any code written beforehand.<|eor|><|eols|><|endoftext|>
7
lolphp
girst
ee4q8f9
<|sols|><|sot|>PHPs fopen() is broken (2017)<|eot|><|sol|>https://arp242.net/weblog/php-fopen-is-broken.html<|eol|><|soopr|>It's been years since I've last touched PHP. Does anyone know if these 7.0 weaknesses were adressed in 7.1 or .2?<|eoopr|><|eols|><|endoftext|>
6
lolphp
barubary
eehl9z4
<|sols|><|sot|>PHPs fopen() is broken (2017)<|eot|><|sol|>https://arp242.net/weblog/php-fopen-is-broken.html<|eol|><|sor|>Pff, a usual blueprint php hatepost. Could be used to slander anything, from bigMac to Tesla > This may or may not work, depending on the value ofallow_url_fopen. Every PHP installation behaves different! This is a trademark statement for this kind. If some feature is configurable, then make a disappointed face and say that every installation "behaves different". <|eor|><|sor|>> Pff, a usual blueprint php hatepost. Could be used to slander anything, from bigMac to Tesla That's not a very effective refutation of the article. I didn't write this just "for the fun" of it, I wrote it because I encountered real problems which I thought and still think are pretty silly. It took me almost 3-and-a-half years to finish writing this, mostly because every time I wanted to publish it I wanted to triple-check that I didn't miss anything. I'm not a huge fan of "zomg, this sucks!" kind of posts (even though I published a few of them), so when you *do* wrote one you better make sure you're correct! Re-reading the article, I think it's mostly on-point, although I'll change some of the wording when I've got some time (as a non-native speaker, I learned a lot about the subtleties of the English language in the last few years on account of living in Ireland, UK, and now NZ). > > This may or may not work, depending on the value of allow_url_fopen. Every PHP installation behaves different! > > This is a trademark statement for this kind. If some feature is configurable, then make a disappointed face and say that every installation "behaves different". I think this is a valid criticism of the PHP language. No other language I know of changes semantics based on an external configuration file. I understand why they did it, as it provides real benefits in allowing to execute "untrusted-ish" code, for example for shared hosting providers. This is a bit less of a concern now, but it was back when shared hosting was more common, and was probably an important reason for PHP's popularity. But the way they did it is rather, eh, suboptimal. Why integrate HTTP in `fopen()`? That's just not a good idea. Validation of pathnames is already hard and many people get it wrong (`../../../../../../etc/passwd`, or `../../config.php` is a common security problem), and with this it's even harder. Are you *sure* there isn't some trick to stuff `http://` in there? The entire API is clunky, as HTTP is much more complex than getting a local file descriptor. Why not a `http_fopen()` or `remote_fopen()`? Why not a `http` namespace with a real HTTP client that can be disabled? Or any number of other options that *remove* a potentially dangerous feature rather than *change semantics* of a common function? All of this was added in PHP 5 (2004), and isn't some sort of legacy thing inherited from PHP 3 or some such. The entire thing was a mistake, and the many security problems that followed from it are the proof. In other words: it's not a bad idea per se, but executed carelessly.<|eor|><|sor|>It is not a semantics, it's a behavior. And it's perfectly valid to make a behavior configurable. And it is not the wording, it's the intention of the article. You don't criticise PHP (which could be perfectly fair), you just hatespeech it, mixing real problems with just a groundless slander. I showed you one example, there are other. When you hate something, you can easily turn *any* feature into a flaw. So your post does. <|eor|><|sor|>> It is not a semantics, it's a behavior. What do you think *semantics* means?<|eor|><|eols|><|endoftext|>
6
lolphp
Schmittfried
ee5r2df
<|sols|><|sot|>PHPs fopen() is broken (2017)<|eot|><|sol|>https://arp242.net/weblog/php-fopen-is-broken.html<|eol|><|sor|>> All of this makes that PHP is not suitable for reliable & robust systems programming, or, indeed, for any sort of programming at all. PHP was never a reliable or robust programming language and it will never be. You will keep on seeing great features being added in PHP but the core will remain the same. On the other hand if you can handle the PHP quirkiness then there is no other language which can beat it. <|eor|><|sor|>>if you can handle the PHP quirkiness then there is no other language which can beat it. Eh, except for almost any other language in existence. And I say this as a regular PHP dev.<|eor|><|eols|><|endoftext|>
5
lolphp
nyamsprod
6sdpmr
<|sols|><|sot|>When is parse_url going to be deprecated ?<|eot|><|sol|>https://3v4l.org/ht82k<|eol|><|eols|><|endoftext|>
35
lolphp
stumpychubbins
dlddihv
<|sols|><|sot|>When is parse_url going to be deprecated ?<|eot|><|sol|>https://3v4l.org/ht82k<|eol|><|sor|>Seems to me somebody should've read [RFC 3986](https://tools.ietf.org/html/rfc3986) before haphazardly implementing something like that. [Here's the PHP source](https://github.com/php/php-src/blob/513b0093c2b480bb752fb354012f42c446769486/ext/standard/url.c#L97-L321). If you ask me, 224 lines of C code seem *a little* on the low end to implement a parser for something that needs 10 chapters and 4 appendices to specify.<|eor|><|soopr|>In defense of `parse_url` the function pre-date RFC3986 so the dev could not have guessed the rules that did not exist back then. Another reason to deprecate/replace the function with a more modern one/valid approach. <|eoopr|><|sor|>Do they also predate RFC 1738? Was `parse_url` written before PHP itself?<|eor|><|sor|>`parse_url` was found in an ancient cave, thought to be previously untouched by human hands. Rasmus, ignoring the cries and protests of his fellows, copied the code into the PHP source. At that moment, PHP became irrevocably cursed.<|eor|><|eols|><|endoftext|>
35
lolphp
andsens
dlc2f21
<|sols|><|sot|>When is parse_url going to be deprecated ?<|eot|><|sol|>https://3v4l.org/ht82k<|eol|><|sor|>Seems to me somebody should've read [RFC 3986](https://tools.ietf.org/html/rfc3986) before haphazardly implementing something like that. [Here's the PHP source](https://github.com/php/php-src/blob/513b0093c2b480bb752fb354012f42c446769486/ext/standard/url.c#L97-L321). If you ask me, 224 lines of C code seem *a little* on the low end to implement a parser for something that needs 10 chapters and 4 appendices to specify.<|eor|><|eols|><|endoftext|>
29
lolphp
nyamsprod
dlc2wfg
<|sols|><|sot|>When is parse_url going to be deprecated ?<|eot|><|sol|>https://3v4l.org/ht82k<|eol|><|sor|>Seems to me somebody should've read [RFC 3986](https://tools.ietf.org/html/rfc3986) before haphazardly implementing something like that. [Here's the PHP source](https://github.com/php/php-src/blob/513b0093c2b480bb752fb354012f42c446769486/ext/standard/url.c#L97-L321). If you ask me, 224 lines of C code seem *a little* on the low end to implement a parser for something that needs 10 chapters and 4 appendices to specify.<|eor|><|soopr|>In defense of `parse_url` the function pre-date RFC3986 so the dev could not have guessed the rules that did not exist back then. Another reason to deprecate/replace the function with a more modern one/valid approach. <|eoopr|><|eols|><|endoftext|>
21