subreddit stringclasses 7
values | author stringlengths 3 20 | id stringlengths 5 7 | content stringlengths 67 30.4k | score int64 0 140k |
|---|---|---|---|---|
lolphp | funtex666 | detupng | <|sols|><|sot|>Test of JSON parsers - PHP's is almost the only one completely correct one.<|eot|><|sol|>http://seriot.ch/json/pruned_results.png<|eol|><|sor|>How is this lol php?<|eor|><|sor|>It's funny that one of the things PHP does correctly is parsing something based on a competing language<|eor|><|sor|>[deleted]<|eor|><|sor|>I can't tell if you're joking. If not: lrn2read.<|eor|><|sor|>apparently I'm not the only one lol, I thought it said JSON was competing with PHP.<|eor|><|sor|>Do you know what JSON stands for?<|eor|><|sor|>JavaScript On Nails<|eor|><|eols|><|endoftext|> | 10 |
lolphp | cfreak2399 | dei6c10 | <|sols|><|sot|>Test of JSON parsers - PHP's is almost the only one completely correct one.<|eot|><|sol|>http://seriot.ch/json/pruned_results.png<|eol|><|sor|>Ironic that the parser is almost to spec when if you want to use the API properly you have to wrap it in a class that will handle errors properly.<|eor|><|sor|>Looks like Python just has one error more and their API is simple and sane.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | RedMser | dehxof1 | <|sols|><|sot|>Test of JSON parsers - PHP's is almost the only one completely correct one.<|eot|><|sol|>http://seriot.ch/json/pruned_results.png<|eol|><|sor|>Has anyone tried this with .NET?<|eor|><|sor|>The table does have a column for "Json.NET 9.0.1", if that's what you were looking for.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | MorrisonLevi | 2v8mbz | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|eoss|><|endoftext|> | 74 |
lolphp | Sarcastinator | cofv5vf | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>You mean to tell me that when you do something stupid, undefined behaviour occurs?
Amazing.<|eor|><|sor|>It may be stupid, but it's documented. (unset) $var does not do anything. [It just returns NULL](http://php.net/manual/en/language.types.null.php). The idea of *casting* a value to *null* is insane as well.<|eor|><|eoss|><|endoftext|> | 32 |
lolphp | allthediamonds | cogg78t | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>You mean to tell me that when you do something stupid, undefined behaviour occurs?
Amazing.<|eor|><|sor|>> You mean to tell me that when you do something stupid, undefined behaviour occurs?
First of all, when I do something stupid, any reasonable language would scream to me, either at compile time or at runtime. It's supposed to be a *productivity tool*, not a freaking Turing tarpit. If I wanted undefined behaviour to occur I'd just, I don't know, write C and jump to random memory pointers.
Second of all, you definitely do not understand how casting in PHP works. This is not undefined behaviour; far from it, this is defined *as hell* behaviour. On PHP, casting instructions are actually *parser tokens*, the actual thing they cast to being hardcoded on each of the tokens. What this means is that they don't appear by accident, that is, `unset()` existing can't somehow have caused `(unset)` to exist.
In other words, there is no chain of causality for `(unset)` to exist other than someone deciding this is a very important feature for PHP and submitting the corresponding pull request, or patch, or tam-tam sounds representing diff output or however those savages communicate, and it being accepted, probably involving some silly RFC vote in which you needed two-thirds of positive votes but you could trade them for sheep at a two-to-one ratio if you had built a village on a port.
What I'm trying to say is that someone actually *came up* with this, decided it was worthy of *existing* and submitted it to a jury of its peers, who also deemed it worthy. On PHP 5, by the way, so you can't even play the legacy card here.<|eor|><|eoss|><|endoftext|> | 27 |
lolphp | gu3st12 | cofm5hc | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>You mean to tell me that when you do something stupid, undefined behaviour occurs?
Amazing.<|eor|><|eoss|><|endoftext|> | 22 |
lolphp | FionaSarah | coi1xpp | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>You mean to tell me that when you do something stupid, undefined behaviour occurs?
Amazing.<|eor|><|sor|>What undefined behaviour? It's documented.
`(unset)` is a misnomer, it's a NULL cast.<|eor|><|sor|>> (unset) is a misnomer, it's a NULL cast.
That has to be the most unintuitive thing I have ever heard.
<|eor|><|sor|>I know, right? I'm struggling to understand why anyone ever thought this was a good id-
OH. OHHHHHHHHHHHHH.
Now I get it. Why is it `(unset)` and not `(NULL)`?
The answer is simple:
some_function(null);
It'd break that, because for some ridiculous reason PHP parses the cast operator as a single token (`T_INT_CAST` for `(int)` etc.) rather than as a bracket, name, end bracket sequence.
(Andi and Zeev, why did you do this, why ;-;)<|eor|><|sor|> > Now I get it. Why is it (unset) and not (NULL)?
> The answer is simple:
> some_function(null);
HAHAHHAHAHHA
Oh my god, I can't breathe. Help.<|eor|><|eoss|><|endoftext|> | 20 |
lolphp | disclosure5 | coggm9n | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>You mean to tell me that when you do something stupid, undefined behaviour occurs?
Amazing.<|eor|><|sor|>What undefined behaviour? It's documented.
`(unset)` is a misnomer, it's a NULL cast.<|eor|><|sor|>> (unset) is a misnomer, it's a NULL cast.
That has to be the most unintuitive thing I have ever heard.
<|eor|><|eoss|><|endoftext|> | 18 |
lolphp | allthediamonds | cogfrg3 | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>[As per today's PHP discussion](http://codelegance.com/embracing-coercion-in-php/), apparently you should be using |0 as a cast.<|eor|><|sor|>They are getting closer and closer to writing asm.js *by hand*.<|eor|><|eoss|><|endoftext|> | 16 |
lolphp | ioctl79 | cogpy5u | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>You mean to tell me that when you do something stupid, undefined behaviour occurs?
Amazing.<|eor|><|sor|>It may be stupid, but it's documented. (unset) $var does not do anything. [It just returns NULL](http://php.net/manual/en/language.types.null.php). The idea of *casting* a value to *null* is insane as well.<|eor|><|sor|>There might be an argument in including it for completeness. But it's called `(unset)` not `(null)` - why?!<|eor|><|sor|>I am guessing that "(null)" would have caused problems with the parser.<|eor|><|eoss|><|endoftext|> | 12 |
lolphp | disclosure5 | cofpwp5 | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>[As per today's PHP discussion](http://codelegance.com/embracing-coercion-in-php/), apparently you should be using |0 as a cast.<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | ahruss | cog48h2 | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>You mean to tell me that when you do something stupid, undefined behaviour occurs?
Amazing.<|eor|><|sor|>What undefined behaviour? It's documented.
`(unset)` is a misnomer, it's a NULL cast.<|eor|><|sor|>[Link to the docs with all the possible casts:](http://php.net/manual/en/language.types.type-juggling.php)
* (int), (integer) - cast to integer
* (bool), (boolean) - cast to boolean
* (float), (double), (real) - cast to float
* (string) - cast to string
* (array) - cast to array
* (object) - cast to object
* (unset) - cast to NULL (PHP 5)
<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | nick_ | cor9clr | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>[As per today's PHP discussion](http://codelegance.com/embracing-coercion-in-php/), apparently you should be using |0 as a cast.<|eor|><|sor|>codelegance.com ___<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | MorrisonLevi | cogh2z4 | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>You mean to tell me that when you do something stupid, undefined behaviour occurs?
Amazing.<|eor|><|sor|>> You mean to tell me that when you do something stupid, undefined behaviour occurs?
First of all, when I do something stupid, any reasonable language would scream to me, either at compile time or at runtime. It's supposed to be a *productivity tool*, not a freaking Turing tarpit. If I wanted undefined behaviour to occur I'd just, I don't know, write C and jump to random memory pointers.
Second of all, you definitely do not understand how casting in PHP works. This is not undefined behaviour; far from it, this is defined *as hell* behaviour. On PHP, casting instructions are actually *parser tokens*, the actual thing they cast to being hardcoded on each of the tokens. What this means is that they don't appear by accident, that is, `unset()` existing can't somehow have caused `(unset)` to exist.
In other words, there is no chain of causality for `(unset)` to exist other than someone deciding this is a very important feature for PHP and submitting the corresponding pull request, or patch, or tam-tam sounds representing diff output or however those savages communicate, and it being accepted, probably involving some silly RFC vote in which you needed two-thirds of positive votes but you could trade them for sheep at a two-to-one ratio if you had built a village on a port.
What I'm trying to say is that someone actually *came up* with this, decided it was worthy of *existing* and submitted it to a jury of its peers, who also deemed it worthy. On PHP 5, by the way, so you can't even play the legacy card here.<|eor|><|soopr|>> but you could trade them for sheep at a two-to-one ratio if you had built a village on a port.
I I understood that reference.
<|eoopr|><|eoss|><|endoftext|> | 8 |
lolphp | MorrisonLevi | coggu8p | <|soss|><|sot|>TIL you can use unset as a cast.<|eot|><|sost|> $apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"
Thank you for this excellent feature, PHP.<|eost|><|sor|>Typecasting never changes the actual value, so I don't know why this is a lolphp. Is it funny just because it is using unset is a "type"?<|eor|><|soopr|>I imagine there are some people out there who would wonder if it unset the value (I mean, this is PHP we are talking about) so I put it there for completeness.<|eoopr|><|eoss|><|endoftext|> | 6 |
lolphp | SaraMG | 5zgur6 | <|sols|><|sot|>Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.<|eot|><|sol|>https://3v4l.org/vUHq3<|eol|><|eols|><|endoftext|> | 73 |
lolphp | SaraMG | dexzzq4 | <|sols|><|sot|>Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.<|eot|><|sol|>https://3v4l.org/vUHq3<|eol|><|soopr|>The result for PHP 7 is particularly lol-worthy.<|eoopr|><|eols|><|endoftext|> | 37 |
lolphp | madsohm | deyarew | <|sols|><|sot|>Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.<|eot|><|sol|>https://3v4l.org/vUHq3<|eol|><|sor|>For people who don't want to look at bit flipping and stuff, here's a string version: https://3v4l.org/sXiiL<|eor|><|eols|><|endoftext|> | 29 |
lolphp | SaraMG | dey1kg0 | <|sols|><|sot|>Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.<|eot|><|sol|>https://3v4l.org/vUHq3<|eol|><|soopr|>PHP is all about having options:
https://3v4l.org/eVLvX
https://3v4l.org/n2hnu <|eoopr|><|eols|><|endoftext|> | 14 |
lolphp | Perdouille | dezyyxo | <|sols|><|sot|>Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.<|eot|><|sol|>https://3v4l.org/vUHq3<|eol|><|sor|>For people who don't want to look at bit flipping and stuff, here's a string version: https://3v4l.org/sXiiL<|eor|><|sor|>BarABarC is the only thing that makes sense... what in the world is this thing doing<|eor|><|sor|>I would've said "FooAFooC" made more sense
But I definitely can't find the logic behind "FooABarC"<|eor|><|eols|><|endoftext|> | 12 |
lolphp | jesseschalken | dey9fsq | <|sols|><|sot|>Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.<|eot|><|sol|>https://3v4l.org/vUHq3<|eol|><|sor|>Good find. Once again HHVM does the sane thing. (`self` always refers to the class the code is written in, `static` refers to the concrete runtime class.)<|eor|><|eols|><|endoftext|> | 10 |
lolphp | edave64 | deygdbr | <|sols|><|sot|>Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.<|eot|><|sol|>https://3v4l.org/vUHq3<|eol|><|sor|>Good find. Once again HHVM does the sane thing. (`self` always refers to the class the code is written in, `static` refers to the concrete runtime class.)<|eor|><|sor|>Except when it says std::bad_alloc.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | ZiggyTheHamster | dez4ria | <|sols|><|sot|>Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.<|eot|><|sol|>https://3v4l.org/vUHq3<|eol|><|sor|>For people who don't want to look at bit flipping and stuff, here's a string version: https://3v4l.org/sXiiL<|eor|><|sor|>BarABarC is the only thing that makes sense... what in the world is this thing doing<|eor|><|eols|><|endoftext|> | 9 |
lolphp | bj_christianson | deyncie | <|sols|><|sot|>Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.<|eot|><|sol|>https://3v4l.org/vUHq3<|eol|><|sor|>Good find. Once again HHVM does the sane thing. (`self` always refers to the class the code is written in, `static` refers to the concrete runtime class.)<|eor|><|sor|>Except when it says std::bad_alloc.<|eor|><|sor|>Bug introduced in 3.14, fixed in 3.15. Looks more like an accident than a lapse in HHVMs sanity.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | edave64 | deypg8u | <|sols|><|sot|>Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.<|eot|><|sol|>https://3v4l.org/vUHq3<|eol|><|sor|>Good find. Once again HHVM does the sane thing. (`self` always refers to the class the code is written in, `static` refers to the concrete runtime class.)<|eor|><|sor|>Except when it says std::bad_alloc.<|eor|><|sor|>Bug introduced in 3.14, fixed in 3.15. Looks more like an accident than a lapse in HHVMs sanity.<|eor|><|sor|>Yes, but the bad alloc thing seems to be a trend if you look at the other eval links in this subreddit. Maybe that version was just really broken.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | pacotes | 3nka8j | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|eols|><|endoftext|> | 73 |
lolphp | AngularSpecter | cvovfsn | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>is escapeshellargs not good enough for that?<|eor|><|soopr|>escapeshellargs has had several bypasses in the past (as recently as 2013 at least, and I vaguely recall a more recent one). Furthermore, this indicates that www-data user is being given sudo access to mount/umount, which is a whole other set of problems... <|eoopr|><|sor|>So if you had to write a file manager that exposes a server's file system over HTTP, what would you do in order to support mounting drives?<|eor|><|sor|>You build an interface.
I would write a daemon to run in the background that had the permissions to mount drives. It would bind to a port on localhost to use TCP sockets for interprocess communication.
If the php needs to mount a drive, it uses standard php level functions to pass the required args to the daemon. The daemon then validates the inputs and returns the mount point to the php.
That allows the program "with the keys to the castle" to remain isolated and only respond to specific "white listed" commands. This way you can also add fun features, like logging mount activity, timing out mount points, cleaning up dead mounts, etc outside of the php.<|eor|><|eols|><|endoftext|> | 47 |
lolphp | user0x29a | cvp3zjm | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>i wonder how many people expect a python project when they read pydio<|eor|><|eols|><|endoftext|> | 40 |
lolphp | pacotes | cvotmta | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>is escapeshellargs not good enough for that?<|eor|><|soopr|>escapeshellargs has had several bypasses in the past (as recently as 2013 at least, and I vaguely recall a more recent one). Furthermore, this indicates that www-data user is being given sudo access to mount/umount, which is a whole other set of problems... <|eoopr|><|eols|><|endoftext|> | 36 |
lolphp | jadkik94 | cvp7jb0 | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>i wonder how many people expect a python project when they read pydio<|eor|><|sor|>I expect a python script that plays Dio songs.<|eor|><|eols|><|endoftext|> | 29 |
lolphp | YouBecame | cvoyqht | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>I read the method name as "escapes hell args. "<|eor|><|eols|><|endoftext|> | 25 |
lolphp | iheartrms | cvp4ax6 | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>is escapeshellargs not good enough for that?<|eor|><|soopr|>escapeshellargs has had several bypasses in the past (as recently as 2013 at least, and I vaguely recall a more recent one). Furthermore, this indicates that www-data user is being given sudo access to mount/umount, which is a whole other set of problems... <|eoopr|><|sor|>So if you had to write a file manager that exposes a server's file system over HTTP, what would you do in order to support mounting drives?<|eor|><|sor|>Why would you ever what to do that? It sounds like a really really bad idea.<|eor|><|sor|>Think UI for a NAS. Some of the operations will require root rights. Either you don't support some features (but keep in mind the competition might support them), or you really really carefully implement something that allows you to execute commands as root.
Sudo is one of these really carefully implemented solutions and when used in conjunction with a correctly implemented escaping mechanism it's as safe as anything else. <|eor|><|sor|>And this is how we end up with security disasters, kids.<|eor|><|eols|><|endoftext|> | 23 |
lolphp | pacotes | cvp6xml | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>The scary thing is that before this commit there was no escape at all.<|eor|><|soopr|>****bingo****
The rest of the project is all similarly disgusting code, btw. Its chock full of bugs. Highly recommend it as a learning experience for anyone interested in learning to audit PHP code, lol.<|eoopr|><|eols|><|endoftext|> | 22 |
lolphp | yrro | cvp3xw9 | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>is escapeshellargs not good enough for that?<|eor|><|soopr|>escapeshellargs has had several bypasses in the past (as recently as 2013 at least, and I vaguely recall a more recent one). Furthermore, this indicates that www-data user is being given sudo access to mount/umount, which is a whole other set of problems... <|eoopr|><|sor|>So if you had to write a file manager that exposes a server's file system over HTTP, what would you do in order to support mounting drives?<|eor|><|sor|>You build an interface.
I would write a daemon to run in the background that had the permissions to mount drives. It would bind to a port on localhost to use TCP sockets for interprocess communication.
If the php needs to mount a drive, it uses standard php level functions to pass the required args to the daemon. The daemon then validates the inputs and returns the mount point to the php.
That allows the program "with the keys to the castle" to remain isolated and only respond to specific "white listed" commands. This way you can also add fun features, like logging mount activity, timing out mount points, cleaning up dead mounts, etc outside of the php.<|eor|><|sor|>> I would write a daemon to run in the background that had the permissions to mount drives.
Interestingly, this already exists in the form of udisks.<|eor|><|eols|><|endoftext|> | 21 |
lolphp | iheartrms | cvp4bgw | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>i wonder how many people expect a python project when they read pydio<|eor|><|sor|>I sure did. <|eor|><|eols|><|endoftext|> | 20 |
lolphp | tdammers | cvp8jen | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>is escapeshellargs not good enough for that?<|eor|><|sor|>`escapeshellargs` is fundamentally wrong because there is absolutely no reason for there to be a shell involved at all. All you want is to spawn a subprocess and pass some arguments to it; PHP does this by concatenating the command and arguments into a string and feeding that to `sh` or `bash`, which means that instead of just passing arguments to a subprocess, we are running a full-blown shell script, and this is what makes the whole thing so fucking dangerous. One mistake, and our shell script can do anything. If no shell were involved, the worst that could happen would be that our subprocess receives the wrong arguments; there's still room for abuse, but if the command in the subprocess is, say, `ls`, there's only so much damage that can be done this way, and passing stuff like `;` or `>>` remains completely benign.<|eor|><|eols|><|endoftext|> | 19 |
lolphp | masklinn | cvqdl65 | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>So now we're just posting any shitty code we find to this sub?
/r/badcode<|eor|><|sor|>Well, the fact that PHP has no portable way to run an external command *without* a shell is one of the driving factors behind the code being terrible. It fits here.<|eor|><|sor|>> PHP has no portable way to run an external command without a shell
I didn't believe you.
I checked.
[I found this](http://stackoverflow.com/questions/16595044/run-executable-from-php-without-spawning-a-shell).
Out of 6 builtin functions to execute external commands (exec(), shell_exec(), passthru(), system(), proc_open() and popen()), 6 spawn a shell, that's a downright impressive level of suck. Apparently the only way to *not* spawn a shell is to use [PNCTL](http://php.net/manual/en/book.pcntl.php) which may not be installed and seems to only be available in PHP/CLI.<|eor|><|eols|><|endoftext|> | 16 |
lolphp | dotted | cvpesxd | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>is escapeshellargs not good enough for that?<|eor|><|soopr|>escapeshellargs has had several bypasses in the past (as recently as 2013 at least, and I vaguely recall a more recent one). Furthermore, this indicates that www-data user is being given sudo access to mount/umount, which is a whole other set of problems... <|eoopr|><|sor|>So if you had to write a file manager that exposes a server's file system over HTTP, what would you do in order to support mounting drives?<|eor|><|sor|>You build an interface.
I would write a daemon to run in the background that had the permissions to mount drives. It would bind to a port on localhost to use TCP sockets for interprocess communication.
If the php needs to mount a drive, it uses standard php level functions to pass the required args to the daemon. The daemon then validates the inputs and returns the mount point to the php.
That allows the program "with the keys to the castle" to remain isolated and only respond to specific "white listed" commands. This way you can also add fun features, like logging mount activity, timing out mount points, cleaning up dead mounts, etc outside of the php.<|eor|><|sor|>This way you move the burden of handling security critical stuff into a daemon that's constantly running. Worse: It has to run as root because mounting requires root privileges.
Of course you can secure your daemon and keep a list of allowed commands, but at that point you're starting to reimplement `sudo` (which already has a config to allow it only for specific commands).
The advantage of sudo of course is that you remove the need to keep a daemon running and to secure it. You also profit from an existing solution that's battle-tested.
Yes. You rely on `escapeshellargs()` working correctly, but at least when a bug is found in there, your and all other solutions are fixed at the same time.<|eor|><|sor|>The daemon already exists and it is called udisks2.
The notion of calling sudo from php is pure insanity, especially since you need to enable passwordless sudo for it to even work in the first place.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | tdammers | cvp8kbk | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>And let's not forget that this requires **passwordless sudo**, which is *never* a good idea for systems storing anything worth anything at all.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | 00Davo | cvpwufq | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>So now we're just posting any shitty code we find to this sub?
/r/badcode<|eor|><|sor|>Well, the fact that PHP has no portable way to run an external command *without* a shell is one of the driving factors behind the code being terrible. It fits here.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | user0x29a | cvp7d4w | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>The scary thing is that before this commit there was no escape at all.<|eor|><|soopr|>****bingo****
The rest of the project is all similarly disgusting code, btw. Its chock full of bugs. Highly recommend it as a learning experience for anyone interested in learning to audit PHP code, lol.<|eoopr|><|sor|>good news: now you have the choice between 2 insecure file sharing/collaboration tools and not only owncloud anymore!<|eor|><|eols|><|endoftext|> | 14 |
lolphp | luchs | cvq3okt | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>is escapeshellargs not good enough for that?<|eor|><|soopr|>escapeshellargs has had several bypasses in the past (as recently as 2013 at least, and I vaguely recall a more recent one). Furthermore, this indicates that www-data user is being given sudo access to mount/umount, which is a whole other set of problems... <|eoopr|><|sor|>So if you had to write a file manager that exposes a server's file system over HTTP, what would you do in order to support mounting drives?<|eor|><|sor|>You build an interface.
I would write a daemon to run in the background that had the permissions to mount drives. It would bind to a port on localhost to use TCP sockets for interprocess communication.
If the php needs to mount a drive, it uses standard php level functions to pass the required args to the daemon. The daemon then validates the inputs and returns the mount point to the php.
That allows the program "with the keys to the castle" to remain isolated and only respond to specific "white listed" commands. This way you can also add fun features, like logging mount activity, timing out mount points, cleaning up dead mounts, etc outside of the php.<|eor|><|sor|>That's all well and good, and you're not wrong, but that solution is not an option for users on shared hosted accounts. The software OP submitted is clearly meant to be an out of the box app that works without external dependencies. Your solution is not applicable to the problem being solved.<|eor|><|sor|>Users on shared hosting will never have sudo access or any other way to mount filesystems, so this whole feature doesn't apply to them.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | LinkXXI | cvoutmf | <|sols|><|sot|>Why yes, lets do `sudo mount` in PHP and hope escapeshellargs saves us!<|eot|><|sol|>https://github.com/pydio/pydio-core/commit/2049254e7a215491019d2646a274a8fb1cf29e3b<|eol|><|sor|>is escapeshellargs not good enough for that?<|eor|><|soopr|>escapeshellargs has had several bypasses in the past (as recently as 2013 at least, and I vaguely recall a more recent one). Furthermore, this indicates that www-data user is being given sudo access to mount/umount, which is a whole other set of problems... <|eoopr|><|sor|>So if you had to write a file manager that exposes a server's file system over HTTP, what would you do in order to support mounting drives?<|eor|><|sor|>Why would you ever what to do that? It sounds like a really really bad idea.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | Muchoz | 2dokyy | <|sols|><|sot|>[X-Post ProgrammerHumor] How to generate a random string<|eot|><|sol|>http://i.imgur.com/RwJ0kJB.png<|eol|><|eols|><|endoftext|> | 74 |
lolphp | TheCockBottler | cjrte1c | <|sols|><|sot|>[X-Post ProgrammerHumor] How to generate a random string<|eot|><|sol|>http://i.imgur.com/RwJ0kJB.png<|eol|><|sor|>I thought we all agreed that you only get real entropy when putting a first year CS Student in front of VIM and tell him to close it?<|eor|><|sor|>Isn't that classified as a form of cruel and unusual punishment?<|eor|><|sor|>Yeah... No computer should be subjected to that.<|eor|><|eols|><|endoftext|> | 20 |
lolphp | Varriount | cjrshob | <|sols|><|sot|>[X-Post ProgrammerHumor] How to generate a random string<|eot|><|sol|>http://i.imgur.com/RwJ0kJB.png<|eol|><|sor|>I thought we all agreed that you only get real entropy when putting a first year CS Student in front of VIM and tell him to close it?<|eor|><|sor|>Isn't that classified as a form of cruel and unusual punishment?<|eor|><|eols|><|endoftext|> | 17 |
lolphp | fnzp | cjszp9z | <|sols|><|sot|>[X-Post ProgrammerHumor] How to generate a random string<|eot|><|sol|>http://i.imgur.com/RwJ0kJB.png<|eol|><|sor|>I thought we all agreed that you only get real entropy when putting a first year CS Student in front of VIM and tell him to close it?<|eor|><|sor|>Hah, the average fourth year CS student at my school has never even touched vim.<|eor|><|sor|>They all use emacs? How enlightened!<|eor|><|eols|><|endoftext|> | 8 |
lolphp | Banane9 | cjt5dbj | <|sols|><|sot|>[X-Post ProgrammerHumor] How to generate a random string<|eot|><|sol|>http://i.imgur.com/RwJ0kJB.png<|eol|><|sor|>I thought we all agreed that you only get real entropy when putting a first year CS Student in front of VIM and tell him to close it?<|eor|><|sor|>Hah, the average fourth year CS student at my school has never even touched vim.<|eor|><|sor|>They all use emacs? How enlightened!<|eor|><|sor|>[*Real* programmers use butterflies](http://xkcd.com/378/)!<|eor|><|eols|><|endoftext|> | 7 |
lolphp | aenigmaclamo | cjrwdiq | <|sols|><|sot|>[X-Post ProgrammerHumor] How to generate a random string<|eot|><|sol|>http://i.imgur.com/RwJ0kJB.png<|eol|><|sor|>I thought we all agreed that you only get real entropy when putting a first year CS Student in front of VIM and tell him to close it?<|eor|><|sor|>Hah, the average fourth year CS student at my school has never even touched vim.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | allthediamonds | 29s2it | <|sols|><|sot|>DateTimeImmutable::modify<|eot|><|sol|>http://www.php.net/manual/en/datetimeimmutable.modify.php<|eol|><|eols|><|endoftext|> | 71 |
lolphp | despens | cio070w | <|sols|><|sot|>DateTimeImmutable::modify<|eot|><|sol|>http://www.php.net/manual/en/datetimeimmutable.modify.php<|eol|><|sor|>Seemingly misleading documentation, everything is fine though. This does not modify the object, but returns a modified object.<|eor|><|sor|>On a php level of expectations this is fine, but there really shouldn't be something called Immutable::modify ... This is like the famous button labeled 'start' that you need to use for shutting down the computer. You get used to it, but you actually shouldn't. You should keep demanding better systems, that make you get used to something that actually is worth getting used to.<|eor|><|eols|><|endoftext|> | 35 |
lolphp | wung | ciny3vv | <|sols|><|sot|>DateTimeImmutable::modify<|eot|><|sol|>http://www.php.net/manual/en/datetimeimmutable.modify.php<|eol|><|sor|>Seemingly misleading documentation, everything is fine though. This does not modify the object, but returns a modified object.<|eor|><|eols|><|endoftext|> | 18 |
lolphp | ismtrn | cioa86n | <|sols|><|sot|>DateTimeImmutable::modify<|eot|><|sol|>http://www.php.net/manual/en/datetimeimmutable.modify.php<|eol|><|sor|>Seemingly misleading documentation, everything is fine though. This does not modify the object, but returns a modified object.<|eor|><|sor|>> Seemingly misleading...
> DateTimeImmutable::modify Alters the timestamp
Everything checks out.<|eor|><|sor|>More like plain misleading.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | startwearinggreen | ciourf4 | <|sols|><|sot|>DateTimeImmutable::modify<|eot|><|sol|>http://www.php.net/manual/en/datetimeimmutable.modify.php<|eol|><|sor|>Seemingly misleading documentation, everything is fine though. This does not modify the object, but returns a modified object.<|eor|><|sor|>On a php level of expectations this is fine, but there really shouldn't be something called Immutable::modify ... This is like the famous button labeled 'start' that you need to use for shutting down the computer. You get used to it, but you actually shouldn't. You should keep demanding better systems, that make you get used to something that actually is worth getting used to.<|eor|><|sor|>Er, the DateTimeImmutable class deliberately mirrors the API of the DateTime class.<|eor|><|sor|>Well no, since modify returns a copy for DateTimeImmutable and doesn't for DateTime. It mimics the names, but it doesn't mirror the API.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | jtickle | 1gnoa5 | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|eoss|><|endoftext|> | 74 |
lolphp | epsy | cam4uw5 | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>Maybe they did it so that the $'s would line up on the function signatures.<|eor|><|eoss|><|endoftext|> | 47 |
lolphp | grafilicious | cam3grf | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>isnt it safe to assume that at this point, it is done for consistency?<|eor|><|eoss|><|endoftext|> | 31 |
lolphp | Denommus | cam6khe | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>isnt it safe to assume that at this point, it is done for consistency?<|eor|><|sor|>Is it inconsistent consistency or consistent inconsistency?<|eor|><|sor|>Consistent inconsistency, of course.<|eor|><|eoss|><|endoftext|> | 20 |
lolphp | vytah | cam6isa | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>isnt it safe to assume that at this point, it is done for consistency?<|eor|><|sor|>Consistency with some other similar functions, or consistency with the inconsistency?<|eor|><|sor|>Yes.<|eor|><|eoss|><|endoftext|> | 19 |
lolphp | Jonno_FTW | cammsqd | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>isnt it safe to assume that at this point, it is done for consistency?<|eor|><|sor|>Consistency with some other similar functions, or consistency with the inconsistency?<|eor|><|sor|>Yes.<|eor|><|sor|>This is the essence of PHP.<|eor|><|eoss|><|endoftext|> | 13 |
lolphp | BufferUnderpants | cam48iy | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>There has *got* to be an actual reason. An mind-numbingly obtuse, absurd reason, but at least one.
Why couldn't they have done it as in any other fucking language?<|eor|><|eoss|><|endoftext|> | 12 |
lolphp | BufferUnderpants | cam46l5 | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>isnt it safe to assume that at this point, it is done for consistency?<|eor|><|sor|>Consistency with some other similar functions, or consistency with the inconsistency?<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | wbkang | cam369h | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>The signature of array_reduce looks really insane.<|eor|><|eoss|><|endoftext|> | 9 |
lolphp | BufferUnderpants | cam6vfg | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>There has *got* to be an actual reason. An mind-numbingly obtuse, absurd reason, but at least one.
Why couldn't they have done it as in any other fucking language?<|eor|><|sor|>Guess: Two different people writing the functions independently without communcation or leadership.
I shall now go and look
Edit **wrong** :
Andrei Zmievski 2001-03-11 Added array_reduce()
Andrei Zmievski 2001-03-19 Added array_map()
Hmm, a week is a long time in programming
http://zmievski.org/about/
> Im Andrei Zmievski, a web developer and founding member of Analog, living and working in San Francisco. Along with my Analog colleagues, I work on things like Mapalong and Brooklyn Beta. Prior to forming Analog, I was the Open Source Fellow at Digg and a platform engineer at Yahoo.
> For the past decade, Ive been a core developer of PHP and member of the PHP Group, helping curate development of the worlds most popular web platform. Along the way, I started the PHP-GTK and Smarty projects, co-wrote PHP Developers Cookbook, and architected the upcoming Unicode and internationalization support in PHP.
How did that work out ?
* [PHP's unicode support is basically like playing minesweeper where all the string functions are bombs](http://www.reddit.com/r/lolphp/comments/rscpj/phps_unicode_support_is_basically_like_playing/)
* [For scripts declared as UTF-8, PHP happily adds one NUL byte to your output for each non-ASCII character in the source](http://www.reddit.com/r/lolphp/comments/11yq8y/for_scripts_declared_as_utf8_php_happily_adds_one/)
* [Class names are affected by current locale](http://www.reddit.com/r/lolphp/comments/vwqwy/class_names_are_affected_by_current_locale/)
<|eor|><|sor|>These sorts of incidents make me wish that you could only program publicly if you have a Programmer's License, which could be revoked. This guy is clearly malpracticing all over the way.<|eor|><|eoss|><|endoftext|> | 9 |
lolphp | metamorphosis | camiegh | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>I lose my shit with array_walk and array map, they are similar functions ; albeit one return values and other passes arr as reference but similar in their role. however....
array_map ( callable $callback , array $arr1 [, array $... ] )
array_walk ( array &$array , callable $funcname [, mixed $userdata = NULL ] )
<|eor|><|eoss|><|endoftext|> | 7 |
lolphp | Kwpolska | camt72x | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>so php<|eor|><|sor|>s/bad/php/<|eor|><|sor|>There is no `bad` in OPs post.<|eor|><|eoss|><|endoftext|> | 7 |
lolphp | Porges | car7o1w | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>There has *got* to be an actual reason. An mind-numbingly obtuse, absurd reason, but at least one.
Why couldn't they have done it as in any other fucking language?<|eor|><|sor|>Guess: Two different people writing the functions independently without communcation or leadership.
I shall now go and look
Edit **wrong** :
Andrei Zmievski 2001-03-11 Added array_reduce()
Andrei Zmievski 2001-03-19 Added array_map()
Hmm, a week is a long time in programming
http://zmievski.org/about/
> Im Andrei Zmievski, a web developer and founding member of Analog, living and working in San Francisco. Along with my Analog colleagues, I work on things like Mapalong and Brooklyn Beta. Prior to forming Analog, I was the Open Source Fellow at Digg and a platform engineer at Yahoo.
> For the past decade, Ive been a core developer of PHP and member of the PHP Group, helping curate development of the worlds most popular web platform. Along the way, I started the PHP-GTK and Smarty projects, co-wrote PHP Developers Cookbook, and architected the upcoming Unicode and internationalization support in PHP.
How did that work out ?
* [PHP's unicode support is basically like playing minesweeper where all the string functions are bombs](http://www.reddit.com/r/lolphp/comments/rscpj/phps_unicode_support_is_basically_like_playing/)
* [For scripts declared as UTF-8, PHP happily adds one NUL byte to your output for each non-ASCII character in the source](http://www.reddit.com/r/lolphp/comments/11yq8y/for_scripts_declared_as_utf8_php_happily_adds_one/)
* [Class names are affected by current locale](http://www.reddit.com/r/lolphp/comments/vwqwy/class_names_are_affected_by_current_locale/)
<|eor|><|sor|>So these are more than 12 years old?<|eor|><|sor|>According to the commit log
[array_map](https://github.com/php/php-src/commit/d9aa966a44937f5846fe426644bb0aaa74fc64b3)
haha I just saw this little nugget :
"It can also be used with a null callback to transpose arrays. (Andrei)"
I don't know why the OP mentioned 5.1 & 5.3
hmm, that branch is in PEAR<|eor|><|sor|>>"It can also be used with a null callback to transpose arrays. (Andrei)"
Everybody go home, /r/lolphp is complete <|eor|><|eoss|><|endoftext|> | 6 |
lolphp | Denommus | cam4kim | <|soss|><|sot|>Functional Map() and Reduce() in php 5.3!!!<|eot|><|sost|>I know 5.3 has been around for awhile but until fairly recently, we targeted 5.1 for a wider audience. I'll skip my usual rant about introducing major language features on a minor version number and skip directly to this absurdity:
array array_map ( callable $callback , array $arr1 [, array $... ] )
mixed array_reduce ( array $input , callable $function [, mixed $initial = NULL ] )
I mean FUCK am I ever sick of having to look at the docs any time I use a fucking array function just to find out the fucking parametric order.<|eost|><|sor|>The signature of array_reduce looks really insane.<|eor|><|sor|>It's really not. It's similar to the signature of reduce in other languages. The initial value is useful in some corner cases.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | Sgoettschkes | c05jn4 | <|sols|><|sot|>The only language going against the versioning of bcrypt<|eot|><|sol|>https://i.redd.it/t2ws949ng4431.png<|eol|><|eols|><|endoftext|> | 73 |
lolphp | Sgoettschkes | er1fs6h | <|sols|><|sot|>The only language going against the versioning of bcrypt<|eot|><|sol|>https://i.redd.it/t2ws949ng4431.png<|eol|><|soopr|>I was trying to use bcrypt hashed passwords from our PHP application in another application reading directly from the database. Turns out half the passwords are in the correct format (\`$2a$\`) but the other half is \`$2y$\` which is not understood by the bcrypt library in Elixir (Erlang). Took me a bit to figure out it's because PHP just used an additional version.
​
Bonus points: The suggestion to replace \`$2a$\` with \`$2x$\` was (obviously) not known to anyone. Wouldn't it make more sense to just thread \`$2a$\` as bad and \`$2y$\` as good?<|eoopr|><|eols|><|endoftext|> | 25 |
lolphp | Miserable_Fuck | er2y1zo | <|sols|><|sot|>The only language going against the versioning of bcrypt<|eot|><|sol|>https://i.redd.it/t2ws949ng4431.png<|eol|><|sor|># <|eor|><|eols|><|endoftext|> | 5 |
lolphp | MMauro94 | 4sgcmj | <|sols|><|sot|>On SERIOUSLY malformed URLs, parse_url() MAY return false<|eot|><|sol|>https://i.redd.it/xu4vqtpcbs8x.png<|eol|><|eols|><|endoftext|> | 71 |
lolphp | roodammy44 | d596bjm | <|sols|><|sot|>On SERIOUSLY malformed URLs, parse_url() MAY return false<|eot|><|sol|>https://i.redd.it/xu4vqtpcbs8x.png<|eol|><|sor|>I think the lol here is the documentation. It doesn't tell you in any way what seriously malformed is, or why it "may" return false (or put another way - may return true!)<|eor|><|eols|><|endoftext|> | 35 |
lolphp | Liorithiel | d597j1y | <|sols|><|sot|>On SERIOUSLY malformed URLs, parse_url() MAY return false<|eot|><|sol|>https://i.redd.it/xu4vqtpcbs8x.png<|eol|><|sor|>That looks funny at first, but it's actually implementation of robustness principle "Be conservative in what you send, be liberal in what you accept". As long as the URL can be parsed, even if it's somewhat malformed it might make sense to try and do it.<|eor|><|sor|>Except when the parsed URL is used later for some destructive action. Then you really want to make sure you know about any mistakes as early as possible.<|eor|><|eols|><|endoftext|> | 19 |
lolphp | olsner | d59j1so | <|sols|><|sot|>On SERIOUSLY malformed URLs, parse_url() MAY return false<|eot|><|sol|>https://i.redd.it/xu4vqtpcbs8x.png<|eol|><|sor|>Anybody have an example of a "seriously malformed URL"?<|eor|><|sor|>[deleted]<|eor|><|sor|>I'd say "host:65536" is only a bit malformed.<|eor|><|sor|>[deleted]<|eor|><|sor|>No it's just malformed by one bit. It's the smallest measurable amount of "malform" you could get.<|eor|><|sor|>You have to flip 17 bits to get from 65535 to 65536, that's more bits than can even *exist* in a port number!<|eor|><|eols|><|endoftext|> | 17 |
lolphp | maweki | d59alrc | <|sols|><|sot|>On SERIOUSLY malformed URLs, parse_url() MAY return false<|eot|><|sol|>https://i.redd.it/xu4vqtpcbs8x.png<|eol|><|sor|>Anybody have an example of a "seriously malformed URL"?<|eor|><|sor|>[deleted]<|eor|><|sor|>I'd say "host:65536" is only a bit malformed.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | miggyb | d595g5o | <|sols|><|sot|>On SERIOUSLY malformed URLs, parse_url() MAY return false<|eot|><|sol|>https://i.redd.it/xu4vqtpcbs8x.png<|eol|><|sor|>Better than returning `TRUE` I guess<|eor|><|eols|><|endoftext|> | 10 |
lolphp | perk11 | d5958pw | <|sols|><|sot|>On SERIOUSLY malformed URLs, parse_url() MAY return false<|eot|><|sol|>https://i.redd.it/xu4vqtpcbs8x.png<|eol|><|sor|>That looks funny at first, but it's actually implementation of robustness principle "Be conservative in what you send, be liberal in what you accept". As long as the URL can be parsed, even if it's somewhat malformed it might make sense to try and do it.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | bart2019 | d5aaq8k | <|sols|><|sot|>On SERIOUSLY malformed URLs, parse_url() MAY return false<|eot|><|sol|>https://i.redd.it/xu4vqtpcbs8x.png<|eol|><|sor|>I think the lol here is the documentation. It doesn't tell you in any way what seriously malformed is, or why it "may" return false (or put another way - may return true!)<|eor|><|sor|>No... `false` is the common return value for failure in PHP, but it does *not* imply it may also return `true`. For example, fetching a row from a query in a database will return either the next row as an array or object, or `false` when it fails. Any non-empty array or standardobject is truthy, but never `true`.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | nickguletskii200 | 3wjzqp | <|sols|><|sot|>200 OK: Internal server error!<|eot|><|sol|>https://bugs.php.net/bug.php?id=50921<|eol|><|eols|><|endoftext|> | 72 |
lolphp | edave64 | cxwsv7b | <|sols|><|sot|>200 OK: Internal server error!<|eot|><|sol|>https://bugs.php.net/bug.php?id=50921<|eol|><|sor|>> it turned out that we added the explicit display_errors check for not setting the http 500 response code because Internet Explore will show a custom error page for non-2xx responses if the length of the response body is less than an arbitrary threshold, hence it won't show the error message if we set the http 500.
Wonderful. IE does something stupid, better let the server do something stupid as well!
<|eor|><|eols|><|endoftext|> | 54 |
lolphp | ThisIsADogHello | cxwzbaa | <|sols|><|sot|>200 OK: Internal server error!<|eot|><|sol|>https://bugs.php.net/bug.php?id=50921<|eol|><|sor|>> it turned out that we added the explicit display_errors check for not setting the http 500 response code because Internet Explore will show a custom error page for non-2xx responses if the length of the response body is less than an arbitrary threshold, hence it won't show the error message if we set the http 500.
Wonderful. IE does something stupid, better let the server do something stupid as well!
<|eor|><|sor|>Especially since most everyone else worked around that IE behaviour by padding their error pages with enough commented-out bytes at the end to override that. PHP on the other hand? Unexpected T_PAAMAYIM_NEKUDOTAYIM is no longer an error, HTTP 200!<|eor|><|eols|><|endoftext|> | 33 |
lolphp | milordi | cxwsju6 | <|sols|><|sot|>200 OK: Internal server error!<|eot|><|sol|>https://bugs.php.net/bug.php?id=50921<|eol|><|sor|>>Status: Not a bug
Classic. Sadly, they finally reopened it.<|eor|><|eols|><|endoftext|> | 31 |
lolphp | stfarn | cxxee3r | <|sols|><|sot|>200 OK: Internal server error!<|eot|><|sol|>https://bugs.php.net/bug.php?id=50921<|eol|><|sor|>"i'm afraid we can't do much about this"
This stuff is gold<|eor|><|eols|><|endoftext|> | 15 |
lolphp | maweki | cxwxjjb | <|sols|><|sot|>200 OK: Internal server error!<|eot|><|sol|>https://bugs.php.net/bug.php?id=50921<|eol|><|sor|>Who thought it would be a good idea for the client scripts to have unbuffered access to the socket, negating any chance to set a different status code after writing the first byte?<|eor|><|eols|><|endoftext|> | 12 |
lolphp | myhf | cxxcgok | <|sols|><|sot|>200 OK: Internal server error!<|eot|><|sol|>https://bugs.php.net/bug.php?id=50921<|eol|><|sor|>Who thought it would be a good idea for the client scripts to have unbuffered access to the socket, negating any chance to set a different status code after writing the first byte?<|eor|><|sor|>The ability to set arbitrary headers and stream data at an arbitrary tempo is actually very useful.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | cbraga | cxx4sbf | <|sols|><|sot|>200 OK: Internal server error!<|eot|><|sol|>https://bugs.php.net/bug.php?id=50921<|eol|><|sor|>Who thought it would be a good idea for the client scripts to have unbuffered access to the socket, negating any chance to set a different status code after writing the first byte?<|eor|><|sor|>TBH if the client script sends bytes before validating its response, it's the client script's fault.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | ayanami_rei | 26spvj | <|sols|><|sot|>Cutesy PHP mascot (Be very afraid)<|eot|><|sol|>http://imgur.com/1NowUfu<|eol|><|eols|><|endoftext|> | 73 |
lolphp | iftpadfs | chua7vo | <|sols|><|sot|>Cutesy PHP mascot (Be very afraid)<|eot|><|sol|>http://imgur.com/1NowUfu<|eol|><|sor|>[Factual representation of PHP](http://next.rikunabi.com/tech/contents/ts_report/img/201312/002412/part5_img.jpg)<|eor|><|eols|><|endoftext|> | 27 |
lolphp | Takeoded | ciu3wq | <|sols|><|sot|>get_current_user(): get the on-disk script file's owner, regardless of what user is actually executing the script.<|eot|><|sol|>https://www.php.net/manual/en/function.get-current-user.php<|eol|><|eols|><|endoftext|> | 70 |
lolphp | vytah | ev9hy1h | <|sols|><|sot|>get_current_user(): get the on-disk script file's owner, regardless of what user is actually executing the script.<|eot|><|sol|>https://www.php.net/manual/en/function.get-current-user.php<|eol|><|soopr|>... someone should make a bugreport about the function name being very, very, very wrong.<|eoopr|><|sor|>"WONTFIX use real_get_current_user"<|eor|><|eols|><|endoftext|> | 30 |
lolphp | dotancohen | ev9e3uo | <|sols|><|sot|>get_current_user(): get the on-disk script file's owner, regardless of what user is actually executing the script.<|eot|><|sol|>https://www.php.net/manual/en/function.get-current-user.php<|eol|><|sor|>I've seen this function used instead of [wp_get_current_user()](https://codex.wordpress.org/wp_get_current_user) on at least two occasions. As the dev typically logs into his workstation with the same username that he logs into his test Wordpress install, the problem is not caught until Staging, and then it becomes a head scratcher as everything _looks_ fine.<|eor|><|eols|><|endoftext|> | 22 |
lolphp | Takeoded | ev962yu | <|sols|><|sot|>get_current_user(): get the on-disk script file's owner, regardless of what user is actually executing the script.<|eot|><|sol|>https://www.php.net/manual/en/function.get-current-user.php<|eol|><|soopr|>... someone should make a bugreport about the function name being very, very, very wrong.<|eoopr|><|eols|><|endoftext|> | 15 |
lolphp | kmark937 | evadwou | <|sols|><|sot|>get_current_user(): get the on-disk script file's owner, regardless of what user is actually executing the script.<|eot|><|sol|>https://www.php.net/manual/en/function.get-current-user.php<|eol|><|sor|>This isn't a LOL: it's very common to have a single process for Apache running in a shared hosting environment. In that case, getting the user that Apache runs as would be useless.<|eor|><|sor|>The lol is almost certainly the confusion around what "current" means here<|eor|><|eols|><|endoftext|> | 12 |
lolphp | Altreus | 40se6f | <|sols|><|sot|>Today someone said "PHP7 <3" - which is true. PHP thinks 7 < 3<|eot|><|sol|>https://3v4l.org/N5hXC<|eol|><|eols|><|endoftext|> | 71 |
lolphp | Rhomboid | cywok3d | <|sols|><|sot|>Today someone said "PHP7 <3" - which is true. PHP thinks 7 < 3<|eot|><|sol|>https://3v4l.org/N5hXC<|eol|><|sor|>That's not a lolphp. It's a misunderstanding of how NaN works and the requirement for a strict weak ordering. Comparing anything to NaN results in false. The sort algorithm is going to ask "is 7 < NaN? False." Then it will ask "is NaN < 7? False." That means 7 and NaN are unorderable (i.e. equal), so they are left in their current order since the sort is stable. Then it asks "is NaN < 3? False" and "is 3 < NaN? False". That again means that 3 and NaN are unorderable, which therefore also means they should stay in their current order. It never actually checks if 3 < 7, because that's not necessaryby the properties of a strict weak ordering, if A == B and B == C, then it must be the case that A == C. By violating that requirement, the result is nonsense.
You get the same thing in Python:
>>> sorted([7, float('nan'), 3])
[7, nan, 3]
And other languages won't even let you do such a thing:
>> [7, Float::NAN, 3].sort
ArgumentError: comparison of Fixnum with NaN failed
from (irb):5:in `sort'
from (irb):5
from /usr/bin/irb:11:in `<main>'
<|eor|><|eols|><|endoftext|> | 74 |
lolphp | squiggleslash | cywoswp | <|sols|><|sot|>Today someone said "PHP7 <3" - which is true. PHP thinks 7 < 3<|eot|><|sol|>https://3v4l.org/N5hXC<|eol|><|sor|>That's not a lolphp. It's a misunderstanding of how NaN works and the requirement for a strict weak ordering. Comparing anything to NaN results in false. The sort algorithm is going to ask "is 7 < NaN? False." Then it will ask "is NaN < 7? False." That means 7 and NaN are unorderable (i.e. equal), so they are left in their current order since the sort is stable. Then it asks "is NaN < 3? False" and "is 3 < NaN? False". That again means that 3 and NaN are unorderable, which therefore also means they should stay in their current order. It never actually checks if 3 < 7, because that's not necessaryby the properties of a strict weak ordering, if A == B and B == C, then it must be the case that A == C. By violating that requirement, the result is nonsense.
You get the same thing in Python:
>>> sorted([7, float('nan'), 3])
[7, nan, 3]
And other languages won't even let you do such a thing:
>> [7, Float::NAN, 3].sort
ArgumentError: comparison of Fixnum with NaN failed
from (irb):5:in `sort'
from (irb):5
from /usr/bin/irb:11:in `<main>'
<|eor|><|sor|>No, it's a LOL. Either the sort should treat NAN in a consistent (and detectable) way, or the sort function should throw an error or otherwise show an error has occurred. Pretending to sort the array, essentially returning random garbage, is the worse case scenario here.
<|eor|><|eols|><|endoftext|> | 30 |
lolphp | Rhomboid | cywpa5j | <|sols|><|sot|>Today someone said "PHP7 <3" - which is true. PHP thinks 7 < 3<|eot|><|sol|>https://3v4l.org/N5hXC<|eol|><|sor|>That's not a lolphp. It's a misunderstanding of how NaN works and the requirement for a strict weak ordering. Comparing anything to NaN results in false. The sort algorithm is going to ask "is 7 < NaN? False." Then it will ask "is NaN < 7? False." That means 7 and NaN are unorderable (i.e. equal), so they are left in their current order since the sort is stable. Then it asks "is NaN < 3? False" and "is 3 < NaN? False". That again means that 3 and NaN are unorderable, which therefore also means they should stay in their current order. It never actually checks if 3 < 7, because that's not necessaryby the properties of a strict weak ordering, if A == B and B == C, then it must be the case that A == C. By violating that requirement, the result is nonsense.
You get the same thing in Python:
>>> sorted([7, float('nan'), 3])
[7, nan, 3]
And other languages won't even let you do such a thing:
>> [7, Float::NAN, 3].sort
ArgumentError: comparison of Fixnum with NaN failed
from (irb):5:in `sort'
from (irb):5
from /usr/bin/irb:11:in `<main>'
<|eor|><|sor|>No, it's a LOL. Either the sort should treat NAN in a consistent (and detectable) way, or the sort function should throw an error or otherwise show an error has occurred. Pretending to sort the array, essentially returning random garbage, is the worse case scenario here.
<|eor|><|sor|>You could perhaps make a case that you shouldn't be able to compare a number to NaN, as in the case of Ruby. But that should be a property of the types themselves, not of the sort algorithm. The sort algorithm should have no idea of the semantics of the types it's working with, only that it will attempt to use less-than to order them. If less-than raises an error, then the sort is a malformed operation, but if not, then it's no business of the sort algorithm to inquire further. The sort algorithm should work for any type with a less-than operator that implements a strict weak ordering, and it should have no special knowledge beyond that. You can't expect the sort algorithm to diagnose when the user has violated those requirements, because it's impossible in the general case. For example, C++'s `std::sort()` has the same requirement and the implementation has absolutely no responsibility to detect when you've managed to violate the requirement, the result is simply undefined behavior.
<|eor|><|eols|><|endoftext|> | 29 |
lolphp | Altreus | cyxsglu | <|sols|><|sot|>Today someone said "PHP7 <3" - which is true. PHP thinks 7 < 3<|eot|><|sol|>https://3v4l.org/N5hXC<|eol|><|sor|>That's not a lolphp. It's a misunderstanding of how NaN works and the requirement for a strict weak ordering. Comparing anything to NaN results in false. The sort algorithm is going to ask "is 7 < NaN? False." Then it will ask "is NaN < 7? False." That means 7 and NaN are unorderable (i.e. equal), so they are left in their current order since the sort is stable. Then it asks "is NaN < 3? False" and "is 3 < NaN? False". That again means that 3 and NaN are unorderable, which therefore also means they should stay in their current order. It never actually checks if 3 < 7, because that's not necessaryby the properties of a strict weak ordering, if A == B and B == C, then it must be the case that A == C. By violating that requirement, the result is nonsense.
You get the same thing in Python:
>>> sorted([7, float('nan'), 3])
[7, nan, 3]
And other languages won't even let you do such a thing:
>> [7, Float::NAN, 3].sort
ArgumentError: comparison of Fixnum with NaN failed
from (irb):5:in `sort'
from (irb):5
from /usr/bin/irb:11:in `<main>'
<|eor|><|soopr|>That's the point. In every other language I tried, it either refuses to do it, tells you off, or correctly sorts the rest *and*tells you off.
The point is that PHP silently sorts it incorrectly, and, depending on how you're using it, you might never know why.<|eoopr|><|eols|><|endoftext|> | 18 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.