subreddit stringclasses 7
values | author stringlengths 3 20 | id stringlengths 5 7 | content stringlengths 67 30.4k | score int64 0 140k |
|---|---|---|---|---|
lolphp | myaut | d3wmup1 | <|soss|><|sot|>str_repeat returns NULL on failure<|eot|><|sost|>unlike pretty much everything else in PHP, which returns FALSE for failure, str_repeat returns NULL. also it's undocumented.
<?php var_dump(str_repeat('fo',-1));?>
>Warning: str_repeat(): Second argument has to be greater than or equal to 0 in /in/IuEhp on line 1
>
>NULL<|eost|><|sor|>str_repeat of NULL, however, is empty string: https://3v4l.org/KrYmb<|eor|><|eoss|><|endoftext|> | 21 |
lolphp | Takeoded | d3wolbz | <|soss|><|sot|>str_repeat returns NULL on failure<|eot|><|sost|>unlike pretty much everything else in PHP, which returns FALSE for failure, str_repeat returns NULL. also it's undocumented.
<?php var_dump(str_repeat('fo',-1));?>
>Warning: str_repeat(): Second argument has to be greater than or equal to 0 in /in/IuEhp on line 1
>
>NULL<|eost|><|sor|>str_repeat of NULL, however, is empty string: https://3v4l.org/KrYmb<|eor|><|soopr|>haha nice catch. in PHP's defense tho, if you enable strict_types, you get
>Fatal error: Uncaught TypeError: str_repeat() expects parameter 1 to be string, null given
and well, without strict types, empty string is the best conversion i can think of for (string)NULL<|eoopr|><|eoss|><|endoftext|> | 16 |
lolphp | emilvikstrom | d3wmy7z | <|soss|><|sot|>str_repeat returns NULL on failure<|eot|><|sost|>unlike pretty much everything else in PHP, which returns FALSE for failure, str_repeat returns NULL. also it's undocumented.
<?php var_dump(str_repeat('fo',-1));?>
>Warning: str_repeat(): Second argument has to be greater than or equal to 0 in /in/IuEhp on line 1
>
>NULL<|eost|><|sor|>No, "every other function" does not return false on failure. Some return -1, some return null, some throw an exception, some requires you to call a different function to see if an error occurred.
-1 doesn't meet the pre-conditions of str_repeat. This error is therefore on you, not on PHP. But it would be nice if such problems could be caught earlier, for example by the type system.<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | Takeoded | d3woext | <|soss|><|sot|>str_repeat returns NULL on failure<|eot|><|sost|>unlike pretty much everything else in PHP, which returns FALSE for failure, str_repeat returns NULL. also it's undocumented.
<?php var_dump(str_repeat('fo',-1));?>
>Warning: str_repeat(): Second argument has to be greater than or equal to 0 in /in/IuEhp on line 1
>
>NULL<|eost|><|sor|>No, "every other function" does not return false on failure. Some return -1, some return null, some throw an exception, some requires you to call a different function to see if an error occurred.
-1 doesn't meet the pre-conditions of str_repeat. This error is therefore on you, not on PHP. But it would be nice if such problems could be caught earlier, for example by the type system.<|eor|><|soopr|>indeed some returns -1 (like fseek() ) and some return null (like str_repeat), hell, feof() can even return TRUE for ERROR. but the vast majority of functions return false.
out of the 109 core function wrappers here, 89 of them check for false https://github.com/divinity76/exphp/blob/master/exphp.php<|eoopr|><|eoss|><|endoftext|> | 9 |
lolphp | bart2019 | d3wnrhd | <|soss|><|sot|>str_repeat returns NULL on failure<|eot|><|sost|>unlike pretty much everything else in PHP, which returns FALSE for failure, str_repeat returns NULL. also it's undocumented.
<?php var_dump(str_repeat('fo',-1));?>
>Warning: str_repeat(): Second argument has to be greater than or equal to 0 in /in/IuEhp on line 1
>
>NULL<|eost|><|sor|>No, "every other function" does not return false on failure. Some return -1, some return null, some throw an exception, some requires you to call a different function to see if an error occurred.
-1 doesn't meet the pre-conditions of str_repeat. This error is therefore on you, not on PHP. But it would be nice if such problems could be caught earlier, for example by the type system.<|eor|><|sor|>> Some return -1, some return null, some throw an exception, some requires you to call a different function to see if an error occurred.
I think the most common case is to return `false`. Even if `0` (or `""`) is a perfectly fine valid result, so you have to distinguish between valid and invalid by using `$return === false`.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | kephir | d3zgnky | <|soss|><|sot|>str_repeat returns NULL on failure<|eot|><|sost|>unlike pretty much everything else in PHP, which returns FALSE for failure, str_repeat returns NULL. also it's undocumented.
<?php var_dump(str_repeat('fo',-1));?>
>Warning: str_repeat(): Second argument has to be greater than or equal to 0 in /in/IuEhp on line 1
>
>NULL<|eost|><|sor|>I honestly expected PHP to reverse the string and repeat it abs() number of times.
(On every 2. prime number iteration it would add a random ASCII character, but only on wednesdays.)<|eor|><|sor|>>I honestly expected PHP to reverse the string and repeat it abs() number of times.
Have I written too much PHP in my time when I'm thinking this part is a pretty neat idea?<|eor|><|sor|>Well I thought that too for a second. I'm actually a fulltime PHP dev. <|eor|><|sor|>We have been damaged, we are broken.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | vytah | 2plab0 | <|sols|><|sot|>IP addresses are valid JSON<|eot|><|sol|>https://bugs.php.net/bug.php?id=67923<|eol|><|eols|><|endoftext|> | 24 |
lolphp | pilif | cmydntz | <|sols|><|sot|>IP addresses are valid JSON<|eot|><|sol|>https://bugs.php.net/bug.php?id=67923<|eol|><|sor|>The response in the bug report points out that the reporter is using a join parser that's different from what PHP ships by default.
The reason behind this is that in some people's eyes, the original json decoder is not free software and thus can't be included in a free software distribution (there's a clause in the license that says you can't use it for evil, which is limiting the freedom of the user).
You can't expect php to accept bug reports in software components they have no control over because some distro decided to replace that component with something else.
This should be reported to the upstream of the alternate json decoder or, rather, the distro which did the replacement.
I hate PHP (nearly) as much as the next guy, but I would prefer if we shamed the language based on truly broken stuff and not based on issues introduced by third parties. <|eor|><|eols|><|endoftext|> | 28 |
lolphp | willglynn | cmxum5x | <|sols|><|sot|>IP addresses are valid JSON<|eot|><|sol|>https://bugs.php.net/bug.php?id=67923<|eol|><|sor|>The Javascript Object Notation is correct in assuming that you were passing a (badly formatted) integer object.
Python errors at characters 7-11 (the part that your example truncated).
http://json.org/ shows that objects start with a {, arrays, a [, and numbers (which you seem to have here) just start with digits.
What you have shown is how php deals with numbers that contain more than one decimal point.
var_dump(json_decode('"192.168.1.1"'));
That's the correct way to represent a string in php. An IP is not an integer, nor is it any other type of number. It's a string. It just so happens to consist of digits and delimiters, and we just so happened to borrow the same delimiter that numbers use. <|eor|><|sor|>> What you have shown is how php deals with numbers that contain more than one decimal point.
I'm not sure what you're arguing that PHP should accept JSON numbers that contain more than one dot? Because it shouldn't.
The JSON website shows [this diagram](http://json.org/number.gif) for representing numbers, which permits only a single `.` character. [RFC4627](http://www.ietf.org/rfc/rfc4627.txt) gives the following production:
2.4. Numbers
The representation of numbers is similar to that used in most
programming languages. A number contains an integer component that
may be prefixed with an optional minus sign, which may be followed by
a fraction part and/or an exponent part.
Octal and hex forms are not allowed. Leading zeros are not allowed.
A fraction part is a decimal point followed by one or more digits.
An exponent part begins with the letter E in upper or lowercase,
which may be followed by a plus or minus sign. The E and optional
sign are followed by one or more digits.
Numeric values that cannot be represented as sequences of digits
(such as Infinity and NaN) are not permitted.
number = [ minus ] int [ frac ] [ exp ]
decimal-point = %x2E ; .
digit1-9 = %x31-39 ; 1-9
e = %x65 / %x45 ; e E
exp = e [ minus / plus ] 1*DIGIT
frac = decimal-point 1*DIGIT
int = zero / ( digit1-9 *DIGIT )
minus = %x2D ; -
plus = %x2B ; +
zero = %x30 ; 0
which once again permits only a single decimal point.
The input of `192.168.1.1` is invalid JSON, and the bug report is that the reporter's copy of PHP doesn't produce an error when presented with this invalid input; it instead produces a float and ignores the subsequent decimal points. In other words, it *should* fail, but it doesn't.
It was closed as "not a bug" because [http://3v4l.org/dkcl5](http://3v4l.org/dkcl5) shows PHP erroring out on this input as expected.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | m1ss1ontomars2k4 | cmya07t | <|sols|><|sot|>IP addresses are valid JSON<|eot|><|sol|>https://bugs.php.net/bug.php?id=67923<|eol|><|sor|>IP address parsing is also a good source of "lol C":
$ ping 127.1
PING 127.1 (127.0.0.1): 56 data bytes
$ ping 3232235777
PING 3232235777 (192.168.1.1): 56 data bytes
$ ping 0300.0xa8.257
PING 0300.0xa8.257 (192.168.1.1): 56 data bytes
<|eor|><|sor|>This is not C-specific at all. Computers think human-readable IP addresses are LOL HUMANS. IP addresses are treated by computers as nothing more than 32 bit numbers.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | frezik | cmxwifw | <|sols|><|sot|>IP addresses are valid JSON<|eot|><|sol|>https://bugs.php.net/bug.php?id=67923<|eol|><|sor|>The real lol here might be the [3v4l output](http://3v4l.org/dkcl5), showing different versions doing vastly different things. 5.2.0, 5.2.9 - 5.2.17 shows:
NULL
Fatal error: Call to undefined function json_last_error() in /in/dkcl5 on line 3
Process exited with code 255.
Returning `NULL`, but then also erroring out on the call to try to check for an error?
Then 5.2.1 - 5.2.8 actually returns a string and then errors out looking for the error catching function:
string(11) "192.168.1.1"
Fatal error: Call to undefined function json_last_error() in /in/dkcl5 on line 3
Process exited with code 255.
Does 3v4l have different versions installed with different libraries or configuration?<|eor|><|eols|><|endoftext|> | 12 |
lolphp | kashmill | cn03j22 | <|sols|><|sot|>IP addresses are valid JSON<|eot|><|sol|>https://bugs.php.net/bug.php?id=67923<|eol|><|sor|>The response in the bug report points out that the reporter is using a join parser that's different from what PHP ships by default.
The reason behind this is that in some people's eyes, the original json decoder is not free software and thus can't be included in a free software distribution (there's a clause in the license that says you can't use it for evil, which is limiting the freedom of the user).
You can't expect php to accept bug reports in software components they have no control over because some distro decided to replace that component with something else.
This should be reported to the upstream of the alternate json decoder or, rather, the distro which did the replacement.
I hate PHP (nearly) as much as the next guy, but I would prefer if we shamed the language based on truly broken stuff and not based on issues introduced by third parties. <|eor|><|sor|>Yeah but the response just says "likely", with no followup from the bug reporter. I agree that the language should be the only thing being made fun of here, but I'd want some confirmation other than "yeah you're probably doing something wrong, I'm closing this as 'not a bug'."<|eor|><|sor|>The response says 'likely' in order to give a possible reason why it wouldn't work as expected for the reporter. Stock `json_decode` certainly works as expected, so it's not a bug in PHP<|eor|><|sor|>Still, it's only a possible reason. Offering *some* proof (linking to a live demo of it working, the bug poster coming back and confirming the guess of the bug-closer, *anything*) is preferable to a handwave.<|eor|><|sor|>> Offering some proof
Like the link to 3v41 that has the output of the runs under different versions?<|eor|><|eols|><|endoftext|> | 9 |
lolphp | vsync | cmybcr5 | <|sols|><|sot|>IP addresses are valid JSON<|eot|><|sol|>https://bugs.php.net/bug.php?id=67923<|eol|><|sor|>IP address parsing is also a good source of "lol C":
$ ping 127.1
PING 127.1 (127.0.0.1): 56 data bytes
$ ping 3232235777
PING 3232235777 (192.168.1.1): 56 data bytes
$ ping 0300.0xa8.257
PING 0300.0xa8.257 (192.168.1.1): 56 data bytes
<|eor|><|sor|>Those are intentional.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | pilif | cmykdfi | <|sols|><|sot|>IP addresses are valid JSON<|eot|><|sol|>https://bugs.php.net/bug.php?id=67923<|eol|><|sor|>The response in the bug report points out that the reporter is using a join parser that's different from what PHP ships by default.
The reason behind this is that in some people's eyes, the original json decoder is not free software and thus can't be included in a free software distribution (there's a clause in the license that says you can't use it for evil, which is limiting the freedom of the user).
You can't expect php to accept bug reports in software components they have no control over because some distro decided to replace that component with something else.
This should be reported to the upstream of the alternate json decoder or, rather, the distro which did the replacement.
I hate PHP (nearly) as much as the next guy, but I would prefer if we shamed the language based on truly broken stuff and not based on issues introduced by third parties. <|eor|><|sor|>Yeah but the response just says "likely", with no followup from the bug reporter. I agree that the language should be the only thing being made fun of here, but I'd want some confirmation other than "yeah you're probably doing something wrong, I'm closing this as 'not a bug'."<|eor|><|sor|>The response says 'likely' in order to give a possible reason why it wouldn't work as expected for the reporter. Stock `json_decode` certainly works as expected, so it's not a bug in PHP<|eor|><|eols|><|endoftext|> | 8 |
lolphp | m1ss1ontomars2k4 | cmycxea | <|sols|><|sot|>IP addresses are valid JSON<|eot|><|sol|>https://bugs.php.net/bug.php?id=67923<|eol|><|sor|>IP address parsing is also a good source of "lol C":
$ ping 127.1
PING 127.1 (127.0.0.1): 56 data bytes
$ ping 3232235777
PING 3232235777 (192.168.1.1): 56 data bytes
$ ping 0300.0xa8.257
PING 0300.0xa8.257 (192.168.1.1): 56 data bytes
<|eor|><|sor|>This is not C-specific at all. Computers think human-readable IP addresses are LOL HUMANS. IP addresses are treated by computers as nothing more than 32 bit numbers.<|eor|><|sor|>[`inet_aton(3)`](http://linux.die.net/man/3/inet_aton) is a C-specific function with bizarre extended behavior worthy of a php function. It is called by an enormous range of applications that only bother to sanitize their input for regular dotted-quad format.<|eor|><|sor|>Well, I never argued that C _doesn't_ have its own lol-C features. It's just that IP address parsing is...well, a feature of IP addresses, not C.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | edwardly | cmybmqn | <|sols|><|sot|>IP addresses are valid JSON<|eot|><|sol|>https://bugs.php.net/bug.php?id=67923<|eol|><|sor|>The real lol here might be the [3v4l output](http://3v4l.org/dkcl5), showing different versions doing vastly different things. 5.2.0, 5.2.9 - 5.2.17 shows:
NULL
Fatal error: Call to undefined function json_last_error() in /in/dkcl5 on line 3
Process exited with code 255.
Returning `NULL`, but then also erroring out on the call to try to check for an error?
Then 5.2.1 - 5.2.8 actually returns a string and then errors out looking for the error catching function:
string(11) "192.168.1.1"
Fatal error: Call to undefined function json_last_error() in /in/dkcl5 on line 3
Process exited with code 255.
Does 3v4l have different versions installed with different libraries or configuration?<|eor|><|sor|>It does have different versions installed. They're different versions of the PHP.
PHP 5.2 didn't have the function `json_last_error()` - it was introduced in PHP 5.3. That's why the call to that function fails.
PHP 5.2.9 [had a change](https://github.com/php/php-src/commit/921ea6a4285b6f10f68811e311792dbd3d6d9462) which did fix the weirdness with parsing that string. 5.2.1 [introduced that change](https://github.com/php/php-src/commit/57f295d3a610074fa9863586dcda798007ee44ee) in an attempt to handle more types of strings.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | phillaf | 1n9gg9 | <|soss|><|sot|>Insightful documentation (xpost from /r/PHP)<|eot|><|sost|>Stumbled across this http://www.reddit.com/r/PHP/comments/1n93jz/insightful_documentation/
Edit: [for the lazy](http://www.php.net/manual/en/function.bson-decode.php)<|eost|><|eoss|><|endoftext|> | 27 |
lolphp | nikic | ccglthv | <|soss|><|sot|>Insightful documentation (xpost from /r/PHP)<|eot|><|sost|>Stumbled across this http://www.reddit.com/r/PHP/comments/1n93jz/insightful_documentation/
Edit: [for the lazy](http://www.php.net/manual/en/function.bson-decode.php)<|eost|><|sor|>You have some serious indirection going on here.
1. *click* http://www.reddit.com/r/lolphp/comments/1n9gg9/insightful_documentation_xpost_from_rphp/
2. *click* http://www.reddit.com/r/PHP/comments/1n93jz/insightful_documentation/
3. *click* http://www.php.net/manual/en/function.bson-decode.php
4. Ah, I'm there :)<|eor|><|eoss|><|endoftext|> | 17 |
lolphp | suspiciously_calm | ccgl88m | <|soss|><|sot|>Insightful documentation (xpost from /r/PHP)<|eot|><|sost|>Stumbled across this http://www.reddit.com/r/PHP/comments/1n93jz/insightful_documentation/
Edit: [for the lazy](http://www.php.net/manual/en/function.bson-decode.php)<|eost|><|sor|>We are the 99%! Occupy PHP!<|eor|><|eoss|><|endoftext|> | 12 |
lolphp | fragglet | xknsk | <|sols|><|sot|>Oldie but a goodie: a PHP integer vulnerability from several years ago.<|eot|><|sol|>http://use.perl.org/use.perl.org/_Aristotle/journal/33448.html<|eol|><|eols|><|endoftext|> | 27 |
lolphp | chellomere | c6mwm7y | <|sols|><|sot|>Oldie but a goodie: a PHP integer vulnerability from several years ago.<|eot|><|sol|>http://use.perl.org/use.perl.org/_Aristotle/journal/33448.html<|eol|><|sor|>A further WTF is the needless use of calloc() in the first place:
calloc(EXPR, sizeof(char));
sizeof(char) is always 1, so this is equivalent to malloc(EXPR). For reference, the proper solution to this problem is:
if (PARTIAL_EXPR_1 >= ((SIZE_MAX-PARTIAL_EXPR_3)/PARTIAL_EXPR_2))
return NULL;
return malloc(PARTIAL_EXPR_1*PARTIAL_EXPR_2+PARTIAL_EXPR_3);
assuming the partials never overflow.<|eor|><|sor|>No, it is not equivalent to malloc(EXPR). The difference is that calloc initializes the memory to 0, while malloc does not. Of course, this may not make a difference in this case.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | redalastor | s9wtyw | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|eols|><|endoftext|> | 23 |
lolphp | redalastor | htrpoge | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>This isn't that LOL, or unheard of. Lua also combines arrays and dictionaries into one data type. JavaScript too to some extent. It's a gotcha, but not really a design flaw per se.<|eor|><|soopr|>Read the article. The issue is that combined with PHP's eagerness to cast to numbers it produce surprising results when deserializing JSON which uses strings representing numbers as keys.<|eoopr|><|eols|><|endoftext|> | 12 |
lolphp | Altreus | htq9gq7 | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>Read the docs for json_decode https://www.php.net/manual/en/function.json-decode.php
You can clearly see a optimal second param "associative" which allows you to keep your keys...<|eor|><|sor|>Great, the stupid design choice based on a fundamental misunderstanding of data has a workaround!<|eor|><|eols|><|endoftext|> | 11 |
lolphp | jesseschalken | htqj63g | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>Why do people always refer to a stupidly inefficient polyfill for `array_is_list`? The correct polyfill is:
```php
function array_is_list(array $array): bool {
$i = 0;
foreach ($array as $k => $v) {
if ($k !== $i++) {
return false;
}
}
return true;
}
```
No array copying.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | AyrA_ch | htqd6ac | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>> A list, sometimes also known as an array, is like the name suggests, a list of elements of any type. These elements are ordered, and every element has a numeric index, starting with 0.
And after that the author uses JS as an example, which is funny because arrays in JS are dictionaries too:
> var x=[10,11,12];
> x["test"]=13;
> console.log(x);
< Array(3) [ 10, 11, 12 ]
< 0: 10
< 1: 11
< 2: 12
< length: 3
< test: 13<|eor|><|eols|><|endoftext|> | 9 |
lolphp | funtek | htpu5jg | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>You're just learning the language? Everyone here knows this already<|eor|><|eols|><|endoftext|> | 9 |
lolphp | redalastor | htprmgf | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>LOL a karma whore decided to jump a bandwagon with such a smoking hot stuff<|eor|><|soopr|>PHP developers are ridiculously thin skinned.<|eoopr|><|eols|><|endoftext|> | 9 |
lolphp | tobiasvl | htrky5y | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>This isn't that LOL, or unheard of. Lua also combines arrays and dictionaries into one data type. JavaScript too to some extent. It's a gotcha, but not really a design flaw per se.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | redalastor | htpt7xe | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>LOL a karma whore decided to jump a bandwagon with such a smoking hot stuff<|eor|><|soopr|>PHP developers are ridiculously thin skinned.<|eoopr|><|sor|>Karma whores are known for posting stuff they don't have a clue about<|eor|><|soopr|>Yup, a 9K users sub is definitely where people come for karma. /s<|eoopr|><|eols|><|endoftext|> | 7 |
lolphp | daperson1 | htuezhh | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>Why do people always refer to a stupidly inefficient polyfill for `array_is_list`? The correct polyfill is:
```php
function array_is_list(array $array): bool {
$i = 0;
foreach ($array as $k => $v) {
if ($k !== $i++) {
return false;
}
}
return true;
}
```
No array copying.<|eor|><|sor|>Still linear time, which is pretty absurd all by itself :D<|eor|><|eols|><|endoftext|> | 6 |
lolphp | jesseschalken | htr740r | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>Read the docs for json_decode https://www.php.net/manual/en/function.json-decode.php
You can clearly see a optimal second param "associative" which allows you to keep your keys...<|eor|><|sor|>Im not sure what point youre making. That param decides whether the return is a stdClass or an associative array. The keys are kept regardless, its just the representation that changes.<|eor|><|sor|>The point is that with `associative = false`, you can distinguish between the JSON array `["a", "b"]` and the JSON object `{"0": "a", "1", "b"}`. The first comes out as a PHP `array`, the second comes out as an `stdClass`.
With `associative = true`, they both come out as the same PHP `array`, `["a", "b"]`, which is one of the problems mentioned in the blog post.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | Takeoded | hum3z4d | <|sols|><|sot|>PHP: Frankenstein arrays<|eot|><|sol|>https://vazaha.blog/en/9/php-frankenstein-arrays<|eol|><|sor|>Why do people always refer to a stupidly inefficient polyfill for `array_is_list`? The correct polyfill is:
```php
function array_is_list(array $array): bool {
$i = 0;
foreach ($array as $k => $v) {
if ($k !== $i++) {
return false;
}
}
return true;
}
```
No array copying.<|eor|><|sor|>at least in php <8 pre-increment is faster than post-increment, this should be faster:
```
function array_is_list(array $array): bool {
$i = 0;
foreach ($array as $k => $v) {
if ($k !== $i) {
return false;
}
++$i;
}
return true;
}
```
and given that this polyfil is only relevant in php<8.. yeah. (why? well, let's consider what post-increment actually does: it creates a copy of the number, then increases the original by 1, then returns the copy. comparatively, pre-increment increases the original by 1, and returns it. the same is valid on C/C++ GCC -O0 btw)
"benchmarks" proving my point: https://3v4l.org/iAekR
winners,
php7.4: pre: 16 post: 10 tie: 1
php8.0: pre: 13 post: 1 tie: 0
php8.1: pre: 3 post: 0 tie: 0
(if the tests were ran in a quiet environment with nothing else needing cpu, or if the array was significantly bigger, i believe pre would win every time, and i attribute post's wins to noise tbh..)<|eor|><|eols|><|endoftext|> | 5 |
lolphp | _pauseIt | cnn0if | <|soss|><|sot|>Unholy Trinity<|eot|><|sost|>​
https://preview.redd.it/gnmzztlop8f31.png?width=525&format=png&auto=webp&v=enabled&s=91dd6b124c4a917eabeb2e51e685907dd8fbb471<|eost|><|eoss|><|endoftext|> | 26 |
lolphp | SerdanKK | ewcmzwu | <|soss|><|sot|>Unholy Trinity<|eot|><|sost|>​
https://preview.redd.it/gnmzztlop8f31.png?width=525&format=png&auto=webp&v=enabled&s=91dd6b124c4a917eabeb2e51e685907dd8fbb471<|eost|><|sor|>As much as I think PHP is garbage, nobody would disagree this is how it should work _if_ we were talking about how it works in an `if` statement. `if ([] || "" || "0")` should naturally make sense to be false. The problem is that rather than just coalesce it in `if` statements, they coalesce it in equality checks too... which is unexpected at best.<|eor|><|sor|>>`if ([] || "" || "0")` should naturally make sense to be false.
I disagree. It's pretty much arbitrary.
Empty array has been specialcased as falsy, but only the builtin array type. Any array-like object will be truthy regardless of content. Empty string I can somewhat accept, but the "0" thing is just plain ridiculous.
JS is actually saner in this regard.<|eor|><|eoss|><|endoftext|> | 15 |
lolphp | chierichetto | ewcehec | <|soss|><|sot|>Unholy Trinity<|eot|><|sost|>​
https://preview.redd.it/gnmzztlop8f31.png?width=525&format=png&auto=webp&v=enabled&s=91dd6b124c4a917eabeb2e51e685907dd8fbb471<|eost|><|sor|>Of course they won't be, and you would not want them to be either. But when casted to a boolean, they will evaluate as false.
When checking a string or array, you would want them to be false if they are empty.
When would anyone want to check if an empty array is equal to an empty string?<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | _pauseIt | ewc2rkp | <|soss|><|sot|>Unholy Trinity<|eot|><|sost|>​
https://preview.redd.it/gnmzztlop8f31.png?width=525&format=png&auto=webp&v=enabled&s=91dd6b124c4a917eabeb2e51e685907dd8fbb471<|eost|><|soopr|>Would love to see variations on this. What's the most absurd version you can find?<|eoopr|><|eoss|><|endoftext|> | 7 |
lolphp | SerdanKK | ewcodhw | <|soss|><|sot|>Unholy Trinity<|eot|><|sost|>​
https://preview.redd.it/gnmzztlop8f31.png?width=525&format=png&auto=webp&v=enabled&s=91dd6b124c4a917eabeb2e51e685907dd8fbb471<|eost|><|sor|>I really really really hate to defend PHP, but falsy values are part of other languages too (javascript)<|eor|><|sor|>It's meant to be funny, but other languages being bad doesn't make PHP less bad.<|eor|><|eoss|><|endoftext|> | 7 |
lolphp | redwall_hp | ewd0e5j | <|soss|><|sot|>Unholy Trinity<|eot|><|sost|>​
https://preview.redd.it/gnmzztlop8f31.png?width=525&format=png&auto=webp&v=enabled&s=91dd6b124c4a917eabeb2e51e685907dd8fbb471<|eost|><|sor|>I really really really hate to defend PHP, but falsy values are part of other languages too (javascript)<|eor|><|sor|>JavaScript isn't a shining example of sanity either. It's bad when it does these things too.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | FlyLo11 | ewde24e | <|soss|><|sot|>Unholy Trinity<|eot|><|sost|>​
https://preview.redd.it/gnmzztlop8f31.png?width=525&format=png&auto=webp&v=enabled&s=91dd6b124c4a917eabeb2e51e685907dd8fbb471<|eost|><|soopr|>Would love to see variations on this. What's the most absurd version you can find?<|eoopr|><|sor|>I'll just leave this here
http://thecodelesscode.com/case/161<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | phplovesong | c4k7ld | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|eoss|><|endoftext|> | 25 |
lolphp | tdammers | erx4p6v | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>PHP doesn't really manage unicode at all. They tried, and that was one of the factors that led to PHP 6 never becoming a thing. So instead, they decided to not have unicode strings at all - you only get byte arrays (which you may write as string literals). If you want actual strings, you have to implement most of it yourself, PHP only gives you a couple of primitives that you can use to operate on various string encodings (including utf-8 and other Unicode encodings) at the byte array level.
So basically much the same deal as in C, except that PHP is supposed to be a high-level programming language that takes care of these things for you.<|eor|><|eoss|><|endoftext|> | 21 |
lolphp | shitcanz | erx6fut | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>This is basically what Python had in 2.x. But they did the works and made python 3 fully unicode. Python is such a blessing to work with when having to deal with unicode texts.<|eor|><|eoss|><|endoftext|> | 13 |
lolphp | pease_pudding | ery61rx | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>I honestly don't think it's such a big deal.<|eor|><|eoss|><|endoftext|> | 7 |
lolphp | duskwuff | erzgfv5 | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>> try to keep your sanity in check
Use mb_ functions to deal with characters. Use raw string functions to deal with bytes. It's not hard.<|eor|><|sor|>It is probably not hard if you control the data source for the input, but a typically case for a PHP application might be parsing CSV data from a user upload. Years ago when I had to deal with that issues kept popping up, even if it was just data from one user.<|eor|><|sor|>Unless your separator is a non-ASCII character (which would be very unusual), CSV parsing written without Unicode in mind requires zero changes.<|eor|><|sor|>Without Unicode you dont need mb_ functions also. But a file uploaded from user could be CP-1252 or Unicode, its a mess to deal with.<|eor|><|sor|>Thats a mess to deal with in *any* language.<|eor|><|eoss|><|endoftext|> | 7 |
lolphp | the_alias_of_andrea | erxyzka | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>This is basically what Python had in 2.x. But they did the works and made python 3 fully unicode. Python is such a blessing to work with when having to deal with unicode texts.<|eor|><|sor|>Given the regular pain that Python 2 and 3's Unicode handling and the differences between them is at work, I can't agree. Python 2.x had fine Unicode support, it just assumed strings are bytes by default, which is the safer assumption compared to Python 3 assuming the outside world only speaks ASCII if it's in a terminal and breaking things :(<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | the_alias_of_andrea | eryrf9h | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>PHP doesn't really manage unicode at all. They tried, and that was one of the factors that led to PHP 6 never becoming a thing. So instead, they decided to not have unicode strings at all - you only get byte arrays (which you may write as string literals). If you want actual strings, you have to implement most of it yourself, PHP only gives you a couple of primitives that you can use to operate on various string encodings (including utf-8 and other Unicode encodings) at the byte array level.
So basically much the same deal as in C, except that PHP is supposed to be a high-level programming language that takes care of these things for you.<|eor|><|sor|>How are byte strings not "actual strings"? There is no correct representation of a Unicode string, each has its own tradeoffs.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | the_alias_of_andrea | es6wwnj | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>I honestly don't think it's such a big deal.<|eor|><|sor|>Its not a big deal until you build support for other languages, with non ascii chars. PHP fails miserably here.<|eor|><|sor|>Only if you use the wrong functions.<|eor|><|sor|>Much in the same way that C is a perfectly safe language as long as you don't use the wrong operations on pointers.<|eor|><|sor|>But the wrong operations in PHP are actually correct and useful in some situations, and aren't unsafe.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | the_alias_of_andrea | es0q0by | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>> try to keep your sanity in check
Use mb_ functions to deal with characters. Use raw string functions to deal with bytes. It's not hard.<|eor|><|sor|>It is probably not hard if you control the data source for the input, but a typically case for a PHP application might be parsing CSV data from a user upload. Years ago when I had to deal with that issues kept popping up, even if it was just data from one user.<|eor|><|sor|>Unless your separator is a non-ASCII character (which would be very unusual), CSV parsing written without Unicode in mind requires zero changes.<|eor|><|sor|>Without Unicode you dont need mb_ functions also. But a file uploaded from user could be CP-1252 or Unicode, its a mess to deal with.<|eor|><|sor|>Thats a mess to deal with in *any* language.<|eor|><|sor|>Its not that level of mess if strings are multibyte/unicode by default, or bytes (byte strings) otherwise.<|eor|><|sor|>No, that turns it into more of a mess, because then you have to make possibly-incorrect assumptions about the encoding of your input.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | hillgod | erz2xma | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>This is basically what Python had in 2.x. But they did the works and made python 3 fully unicode. Python is such a blessing to work with when having to deal with unicode texts.<|eor|><|sor|>Given the regular pain that Python 2 and 3's Unicode handling and the differences between them is at work, I can't agree. Python 2.x had fine Unicode support, it just assumed strings are bytes by default, which is the safer assumption compared to Python 3 assuming the outside world only speaks ASCII if it's in a terminal and breaking things :(<|eor|><|sor|>Python had shitty PHP style second tier support for Unicode in v2, and v2 had a future port to treat strings as all one format, like most every other language, shortly thereafter. No one wants to deal with Unicode vs ASCII, and it's even more insane if you start to consider the world before Unicode and get outside the US (Japanese Kanji, anyone???).
What makes more sense... Designing for the most common use cases (utf-8 on web, etc) vs keeping everything ASCII due to some locally run console app? If language uptake and joy of use from dev surveys is any indication, it's clearly the former.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | the_alias_of_andrea | es0py9o | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>I honestly don't think it's such a big deal.<|eor|><|sor|>Its not a big deal until you build support for other languages, with non ascii chars. PHP fails miserably here.<|eor|><|sor|>Only if you use the wrong functions.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | the_alias_of_andrea | es0prnd | <|soss|><|sot|>The state of PHP unicode in 2019<|eot|><|sost|>One of multiple lolphps is how poorly PHP manages unicode. Its a web language and you must deal with the multitude of mb\_ functions and at the same time try to keep your sanity in check.
​
[https://www.php.net/manual/en/ref.mbstring.php](https://www.php.net/manual/en/ref.mbstring.php)<|eost|><|sor|>This is basically what Python had in 2.x. But they did the works and made python 3 fully unicode. Python is such a blessing to work with when having to deal with unicode texts.<|eor|><|sor|>Given the regular pain that Python 2 and 3's Unicode handling and the differences between them is at work, I can't agree. Python 2.x had fine Unicode support, it just assumed strings are bytes by default, which is the safer assumption compared to Python 3 assuming the outside world only speaks ASCII if it's in a terminal and breaking things :(<|eor|><|sor|>Python had shitty PHP style second tier support for Unicode in v2, and v2 had a future port to treat strings as all one format, like most every other language, shortly thereafter. No one wants to deal with Unicode vs ASCII, and it's even more insane if you start to consider the world before Unicode and get outside the US (Japanese Kanji, anyone???).
What makes more sense... Designing for the most common use cases (utf-8 on web, etc) vs keeping everything ASCII due to some locally run console app? If language uptake and joy of use from dev surveys is any indication, it's clearly the former.<|eor|><|sor|>This isn't true. Python 2 and 3 are not fundamentally different on Unicode handling, both have two string types. If Python 3 has good Unicode handling, so did Python 2. The main difference is that Python 3 did a sweeping change of syntax and default types, which broke a huge amount of existing code and made ensuring backwards or forwards compatibility needlessly painful, and that Python 3 tries to convert everything into Unicode by default and makes bad assumptions about the outside world when it does so.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | TortoiseWrath | 79iifz | <|soss|><|sot|>Checking the parameter order for file_put_contents when suddenly<|eot|><|sost|>> You can also specify the `data` parameter as a single dimension array. This is equivalent to `file_put_contents($filename, implode('', $array))`.
why<|eost|><|eoss|><|endoftext|> | 26 |
lolphp | squiggleslash | dp29o1l | <|soss|><|sot|>Checking the parameter order for file_put_contents when suddenly<|eot|><|sost|>> You can also specify the `data` parameter as a single dimension array. This is equivalent to `file_put_contents($filename, implode('', $array))`.
why<|eost|><|sor|>I was going to say it makes sense for different operating systems that have different EOL markers (Unix LF, Windows CR+LF, MacOS CR, etc), and was going to see if file_get_contents had the ability to return an array...
...when I looked again and saw it was just appending the array elements, not adding line breaks between them. So file_put_contents('status.txt', array('PEN', 'IS', 'UP')) outputs 'PENISUP' to status.txt, not PEN (linebreak) IS (linebreak) UP.
Which is useless. I'll allow it, definitely a minor LOL.<|eor|><|eoss|><|endoftext|> | 24 |
lolphp | TortoiseWrath | dp2gnaz | <|soss|><|sot|>Checking the parameter order for file_put_contents when suddenly<|eot|><|sost|>> You can also specify the `data` parameter as a single dimension array. This is equivalent to `file_put_contents($filename, implode('', $array))`.
why<|eost|><|sor|>I was going to say it makes sense for different operating systems that have different EOL markers (Unix LF, Windows CR+LF, MacOS CR, etc), and was going to see if file_get_contents had the ability to return an array...
...when I looked again and saw it was just appending the array elements, not adding line breaks between them. So file_put_contents('status.txt', array('PEN', 'IS', 'UP')) outputs 'PENISUP' to status.txt, not PEN (linebreak) IS (linebreak) UP.
Which is useless. I'll allow it, definitely a minor LOL.<|eor|><|sor|>[deleted]<|eor|><|soopr|>Wow, TIL `file()` exists. But why would you ever want an array of the lines *with* the line breaks at the end of each value? Other than to write it out with `file_put_contents()` which doesn't add line breaks...
It's like each function is designed in an illogical way so that it works nicely with a different function that is designed in an illogical way. I suppose that is The PHP Way.<|eoopr|><|eoss|><|endoftext|> | 19 |
lolphp | TortoiseWrath | dp29s5s | <|soss|><|sot|>Checking the parameter order for file_put_contents when suddenly<|eot|><|sost|>> You can also specify the `data` parameter as a single dimension array. This is equivalent to `file_put_contents($filename, implode('', $array))`.
why<|eost|><|sor|>I was going to say it makes sense for different operating systems that have different EOL markers (Unix LF, Windows CR+LF, MacOS CR, etc), and was going to see if file_get_contents had the ability to return an array...
...when I looked again and saw it was just appending the array elements, not adding line breaks between them. So file_put_contents('status.txt', array('PEN', 'IS', 'UP')) outputs 'PENISUP' to status.txt, not PEN (linebreak) IS (linebreak) UP.
Which is useless. I'll allow it, definitely a minor LOL.<|eor|><|soopr|>It's just one of those little things in the library that doesn't make sense. One of the thousands of them that make the entire library a laughing stock. <|eoopr|><|eoss|><|endoftext|> | 18 |
lolphp | cfreak2399 | dp3a5eg | <|soss|><|sot|>Checking the parameter order for file_put_contents when suddenly<|eot|><|sost|>> You can also specify the `data` parameter as a single dimension array. This is equivalent to `file_put_contents($filename, implode('', $array))`.
why<|eost|><|sor|>I was going to say it makes sense for different operating systems that have different EOL markers (Unix LF, Windows CR+LF, MacOS CR, etc), and was going to see if file_get_contents had the ability to return an array...
...when I looked again and saw it was just appending the array elements, not adding line breaks between them. So file_put_contents('status.txt', array('PEN', 'IS', 'UP')) outputs 'PENISUP' to status.txt, not PEN (linebreak) IS (linebreak) UP.
Which is useless. I'll allow it, definitely a minor LOL.<|eor|><|sor|>[deleted]<|eor|><|soopr|>Wow, TIL `file()` exists. But why would you ever want an array of the lines *with* the line breaks at the end of each value? Other than to write it out with `file_put_contents()` which doesn't add line breaks...
It's like each function is designed in an illogical way so that it works nicely with a different function that is designed in an illogical way. I suppose that is The PHP Way.<|eoopr|><|sor|>[deleted]<|eor|><|sor|>I agree with this. The LOL here is that the oldest parts of PHP are Perl-like, then they decided to be Java-like and most recently Python-like. I cant wait for their Node phase to start.
Perhaps we can expect PHP to gain its own identity in its 20s like most people <|eor|><|eoss|><|endoftext|> | 15 |
lolphp | Takeoded | dp3vfyq | <|soss|><|sot|>Checking the parameter order for file_put_contents when suddenly<|eot|><|sost|>> You can also specify the `data` parameter as a single dimension array. This is equivalent to `file_put_contents($filename, implode('', $array))`.
why<|eost|><|sor|>well, the implode approach would make an entire concatenated string in memory before file_put_contents is called - but when you give the array directly, file_put_contents *might* be optimized to not create that entire string in memory like implode would do, and thus be less memory hungry... possibly (then possibly at the cost of doing more write() calls, if theres metadata between the members or the members are not in a contiguous memory block)<|eor|><|eoss|><|endoftext|> | 7 |
lolphp | sourtin_ | 65wu9y | <|soss|><|sot|>Substituting variables in error messages...<|eot|><|sost|>So the webhost for a site I manage is upgrading their servers soon, distro, PHP version, etc, and to help their clients prepare they have setup a convenient test server. As the old server ran php5 and the new one php7, I expected some breaking changes so dutifully checked out the damage.
Naturally, I encounter a fatal error. The mild annoyance rapidly transcends to panic, though, as I discover the database password is printed in this fatal error! Now, perhaps the host should have disabled error messages, and perhaps the site has a security bug (I inherited the site), but my first priority is to stop the leak and damage assessment.
The error message was something along the lines of
> Fatal error: no function named 'mysql_connect' in mysql->connect('localhost','site-name','db-password') in site.php on line 1337
When I edit site.php and look for the line, though, I can't seem to find it Then I discover the actual line is $sqlobj->connect($dbhost,$dbuser,$dbpass) or die('...').
So, apparently, PHP decided it would be helpful to substitute variables in their error messages... To see it for yourself, here's a minimal working example: https://3v4l.org/rk8NE<|eost|><|eoss|><|endoftext|> | 26 |
lolphp | beerdude26 | dgdymxv | <|soss|><|sot|>Substituting variables in error messages...<|eot|><|sost|>So the webhost for a site I manage is upgrading their servers soon, distro, PHP version, etc, and to help their clients prepare they have setup a convenient test server. As the old server ran php5 and the new one php7, I expected some breaking changes so dutifully checked out the damage.
Naturally, I encounter a fatal error. The mild annoyance rapidly transcends to panic, though, as I discover the database password is printed in this fatal error! Now, perhaps the host should have disabled error messages, and perhaps the site has a security bug (I inherited the site), but my first priority is to stop the leak and damage assessment.
The error message was something along the lines of
> Fatal error: no function named 'mysql_connect' in mysql->connect('localhost','site-name','db-password') in site.php on line 1337
When I edit site.php and look for the line, though, I can't seem to find it Then I discover the actual line is $sqlobj->connect($dbhost,$dbuser,$dbpass) or die('...').
So, apparently, PHP decided it would be helpful to substitute variables in their error messages... To see it for yourself, here's a minimal working example: https://3v4l.org/rk8NE<|eost|><|sor|>[deleted]<|eor|><|sor|>Or just write it to the goddamn server log file like every other sane framework or language<|eor|><|eoss|><|endoftext|> | 14 |
lolphp | prewk | dget1p3 | <|soss|><|sot|>Substituting variables in error messages...<|eot|><|sost|>So the webhost for a site I manage is upgrading their servers soon, distro, PHP version, etc, and to help their clients prepare they have setup a convenient test server. As the old server ran php5 and the new one php7, I expected some breaking changes so dutifully checked out the damage.
Naturally, I encounter a fatal error. The mild annoyance rapidly transcends to panic, though, as I discover the database password is printed in this fatal error! Now, perhaps the host should have disabled error messages, and perhaps the site has a security bug (I inherited the site), but my first priority is to stop the leak and damage assessment.
The error message was something along the lines of
> Fatal error: no function named 'mysql_connect' in mysql->connect('localhost','site-name','db-password') in site.php on line 1337
When I edit site.php and look for the line, though, I can't seem to find it Then I discover the actual line is $sqlobj->connect($dbhost,$dbuser,$dbpass) or die('...').
So, apparently, PHP decided it would be helpful to substitute variables in their error messages... To see it for yourself, here's a minimal working example: https://3v4l.org/rk8NE<|eost|><|sor|>If you've configured your application to show visitors dangerous debug messages, then that's what it'll do.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | sourtin_ | dge1r0m | <|soss|><|sot|>Substituting variables in error messages...<|eot|><|sost|>So the webhost for a site I manage is upgrading their servers soon, distro, PHP version, etc, and to help their clients prepare they have setup a convenient test server. As the old server ran php5 and the new one php7, I expected some breaking changes so dutifully checked out the damage.
Naturally, I encounter a fatal error. The mild annoyance rapidly transcends to panic, though, as I discover the database password is printed in this fatal error! Now, perhaps the host should have disabled error messages, and perhaps the site has a security bug (I inherited the site), but my first priority is to stop the leak and damage assessment.
The error message was something along the lines of
> Fatal error: no function named 'mysql_connect' in mysql->connect('localhost','site-name','db-password') in site.php on line 1337
When I edit site.php and look for the line, though, I can't seem to find it Then I discover the actual line is $sqlobj->connect($dbhost,$dbuser,$dbpass) or die('...').
So, apparently, PHP decided it would be helpful to substitute variables in their error messages... To see it for yourself, here's a minimal working example: https://3v4l.org/rk8NE<|eost|><|sor|>[deleted]<|eor|><|soopr|>Yes I can see it can have valid uses, though I'm not sure why it would be the default behaviour. Talking to the sysadmins, we can't seem to find a flag to disable this behaviour and so have resorted to just disabling all errors for now. For the types of site hosted here, it would actually be preferable _not_ to disable errors (many of those using the host may not have much webdev experience and so benefit from having immediate errors, and the sites are very small scale so often there's no distinction between debug and production, for better or for worse :P)<|eoopr|><|eoss|><|endoftext|> | 5 |
lolphp | pease_pudding | dge5le6 | <|soss|><|sot|>Substituting variables in error messages...<|eot|><|sost|>So the webhost for a site I manage is upgrading their servers soon, distro, PHP version, etc, and to help their clients prepare they have setup a convenient test server. As the old server ran php5 and the new one php7, I expected some breaking changes so dutifully checked out the damage.
Naturally, I encounter a fatal error. The mild annoyance rapidly transcends to panic, though, as I discover the database password is printed in this fatal error! Now, perhaps the host should have disabled error messages, and perhaps the site has a security bug (I inherited the site), but my first priority is to stop the leak and damage assessment.
The error message was something along the lines of
> Fatal error: no function named 'mysql_connect' in mysql->connect('localhost','site-name','db-password') in site.php on line 1337
When I edit site.php and look for the line, though, I can't seem to find it Then I discover the actual line is $sqlobj->connect($dbhost,$dbuser,$dbpass) or die('...').
So, apparently, PHP decided it would be helpful to substitute variables in their error messages... To see it for yourself, here's a minimal working example: https://3v4l.org/rk8NE<|eost|><|sor|>[deleted]<|eor|><|soopr|>Yes I can see it can have valid uses, though I'm not sure why it would be the default behaviour. Talking to the sysadmins, we can't seem to find a flag to disable this behaviour and so have resorted to just disabling all errors for now. For the types of site hosted here, it would actually be preferable _not_ to disable errors (many of those using the host may not have much webdev experience and so benefit from having immediate errors, and the sites are very small scale so often there's no distinction between debug and production, for better or for worse :P)<|eoopr|><|sor|>php.ini -> display_errors
Your hosting provider appears to have deployed a development php.ini, presumably to help you migrate
If these pages are all publicly accessible then sure, its a problem.
But you shouldn't really be relying on your live web host to test a new php anyway.
Set up your own dev server and push it live when its ready. You will need a fair bit of development work on your site anyway, as mysql_* has gone away. Migrate to PDO, or maybe mysqli in a pinch (I really struggle to recommend mysqli functions, the parameter binding api blows)
<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | element131 | dgjcjvs | <|soss|><|sot|>Substituting variables in error messages...<|eot|><|sost|>So the webhost for a site I manage is upgrading their servers soon, distro, PHP version, etc, and to help their clients prepare they have setup a convenient test server. As the old server ran php5 and the new one php7, I expected some breaking changes so dutifully checked out the damage.
Naturally, I encounter a fatal error. The mild annoyance rapidly transcends to panic, though, as I discover the database password is printed in this fatal error! Now, perhaps the host should have disabled error messages, and perhaps the site has a security bug (I inherited the site), but my first priority is to stop the leak and damage assessment.
The error message was something along the lines of
> Fatal error: no function named 'mysql_connect' in mysql->connect('localhost','site-name','db-password') in site.php on line 1337
When I edit site.php and look for the line, though, I can't seem to find it Then I discover the actual line is $sqlobj->connect($dbhost,$dbuser,$dbpass) or die('...').
So, apparently, PHP decided it would be helpful to substitute variables in their error messages... To see it for yourself, here's a minimal working example: https://3v4l.org/rk8NE<|eost|><|sor|>If you've configured your application to show visitors dangerous debug messages, then that's what it'll do.<|eor|><|soopr|>Oh I understand this shouldn't be active on production sites (though it does kinda make sense for this host...). What's most surprising to me is that it's active by default, and so the people it will harm most are newbie programmers who might not know how to deal with it/what they should do if their password is leaked. Also, if you forgot to disable errors it can transiently leak passwords if the database ever [drops a connection](https://blog.hboeck.de/archives/884-And-then-I-saw-the-Password-in-the-Stack-Trace.html).<|eoopr|><|sor|>> What's most surprising to me is that it's active by default
No, [it's not](https://github.com/php/php-src/blob/master/php.ini-production#L477). Unless you're using the development ini file in production.
Not that many people actually install PHP src, so it's possible that it is enabled by default in the package you are using, but that would be the fault of whoever packaged it, not PHP itself.
<|eor|><|sor|>> by default
Yes, [it is](https://github.com/php/php-src/blob/master/php.ini-production#L473).
> If PHP can't find an expected directive because it is not set or is mistyped, a default value will be used.
The **default value** is active. The suggested production value is inactive.<|eor|><|sor|>The default value is used if it's not set in the ini file.
But it is set in the production ini file that is part of the official PHP release, on the line I linked.<|eor|><|sor|>I linked to three lines above the line you did, in the same file, where it says "default value".<|eor|><|sor|>That line is a comment. It tells the reader what the default value that is hard-coded in the line of code where the value [is initialized](https://github.com/php/php-src/blob/06eb61591ad1fdd28c8e68aa05ffaeb40e11187d/main/main.c#L527).
If the value is set in the ini file (which it is), the default value isn't used, but instead the value from the ini file is used.<|eor|><|sor|>I feel like you are either under the mistaken impression that PHP will somehow know to load php.ini-production, without someone needing to do anything, or you have a very strange idea about what a "default value" means.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | Tuxmascot | 5gu22t | <|sols|><|sot|>RIPS - Roundcube 1.2.2: Command Execution via Email<|eot|><|sol|>https://blog.ripstech.com/2016/roundcube-command-execution-via-email/<|eol|><|eols|><|endoftext|> | 27 |
lolphp | emilvikstrom | davqb08 | <|sols|><|sot|>RIPS - Roundcube 1.2.2: Command Execution via Email<|eot|><|sol|>https://blog.ripstech.com/2016/roundcube-command-execution-via-email/<|eol|><|sor|>This is half PHP's fault, half developers'. Bad regex, not DRY, classic code injection vulnerability. The lol is that mail() doesn't provide a parameterized way of setting the envelope sender.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | credditz0rz | 4lb2pi | <|sols|><|sot|>Iterate through UTF-8 string: preg_split is over 20 times faster than mb_substr<|eot|><|sol|>https://stackoverflow.com/questions/3666306/how-to-iterate-utf-8-string-in-php<|eol|><|eols|><|endoftext|> | 25 |
lolphp | BreiteSeite | d3lwsc9 | <|sols|><|sot|>Iterate through UTF-8 string: preg_split is over 20 times faster than mb_substr<|eot|><|sol|>https://stackoverflow.com/questions/3666306/how-to-iterate-utf-8-string-in-php<|eol|><|sor|>This benchmark is completely misleading as mb_substr() is (probably) called many times, increasing the overhead of the profiler by a large amount.
See: https://tideways.io/profiler/blog/profiling-overhead-and-php-7
Also it looks like Xdebug profiling was used, which even makes this worse because it's probably the worst possible profiler regarding to overhead.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | sarciszewski | 44bc1v | <|sols|><|sot|>Anthony Ferrara on Twitter: "TIL: When you turn OFF prepared statement emulation for PDO+PostGreSQL, PDO rewrites the query anyway... https://t.co/bwkiOnACuL #HEADDESK"<|eot|><|sol|>https://twitter.com/ircmaxell/status/695276215897362432<|eol|><|eols|><|endoftext|> | 27 |
lolphp | pilif | czpb398 | <|sols|><|sot|>Anthony Ferrara on Twitter: "TIL: When you turn OFF prepared statement emulation for PDO+PostGreSQL, PDO rewrites the query anyway... https://t.co/bwkiOnACuL #HEADDESK"<|eot|><|sol|>https://twitter.com/ircmaxell/status/695276215897362432<|eol|><|sor|>Maybe I misunderstand, but unless PostgreSQL uses the same syntax as PDO for parameterised queries, surely it *has* to rewrite the query?
EDIT: Anthony explained to me on Twitter that it always rewrites positional parameters to named parameters, despite PostgreSQL supporting both. Weird. It's harmless, though.<|eor|><|sor|>erm... postgres only supports positional parameters. See [PREPARE](http://www.postgresql.org/docs/9.2/static/sql-prepare.html) and [PQprepare](http://www.postgresql.org/docs/9.3/static/libpq-exec.html#LIBPQ-PQPREPARE).
It's mildly better than the pure ? replacements, because the parameters are always explicitly numbered ($1...$n), but they can't be named.
Because PDO supports named parameters, the rewriting still has to happen if you use named parameters.
If you want a real WTF, have a look at the PDO function name conventions like [ pgsql_handle_doer](http://lxr.php.net/xref/PHP_5_6/ext/pdo_pgsql/pgsql_driver.c#303) which seem to be firmly placed in the [Kingdom of Nouns](http://steve-yegge.blogspot.ch/2006/03/execution-in-kingdom-of-nouns.html), despite all being functions which should be verbs (also: handle doer? Do what?).
<|eor|><|eols|><|endoftext|> | 11 |
lolphp | the_alias_of_andrea | czp5z0l | <|sols|><|sot|>Anthony Ferrara on Twitter: "TIL: When you turn OFF prepared statement emulation for PDO+PostGreSQL, PDO rewrites the query anyway... https://t.co/bwkiOnACuL #HEADDESK"<|eot|><|sol|>https://twitter.com/ircmaxell/status/695276215897362432<|eol|><|sor|>Maybe I misunderstand, but unless PostgreSQL uses the same syntax as PDO for parameterised queries, surely it *has* to rewrite the query?
EDIT: Anthony explained to me on Twitter that it always rewrites positional parameters to named parameters, despite PostgreSQL supporting both. Weird. It's harmless, though.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | fnzp | 25b4k5 | <|soss|><|sot|>exec returns string... wait... exec returns?<|eot|><|sost|>*Return Values: The last line from the result of the command.* [http://www.php.net/manual/en/function.exec.php]
In C, shell, perl, and ruby, exec doesn't return. The calling process is overwritten. You would use system() if you want it to return.
In PHP, system executes a command and displays the output. Exec is just like system, except it doesn't display the output.<|eost|><|eoss|><|endoftext|> | 27 |
lolphp | duskwuff | chfinj5 | <|soss|><|sot|>exec returns string... wait... exec returns?<|eot|><|sost|>*Return Values: The last line from the result of the command.* [http://www.php.net/manual/en/function.exec.php]
In C, shell, perl, and ruby, exec doesn't return. The calling process is overwritten. You would use system() if you want it to return.
In PHP, system executes a command and displays the output. Exec is just like system, except it doesn't display the output.<|eost|><|sor|>PHP does have [`pcntl_exec`](http://php.net/pcntl_exec) if you want the real thing.
But it's *never* something that you actually want. Calling `execve()` in a web server, or in a FastCGI worker, will leave the new process completely dazed and confused, with a bunch of file descriptors it doesn't know what to do with, and a parent that's expecting it to get back to its normal job once it's done handling this request. You can lead up to it with [`pcntl_fork`](http://php.net/pcntl_fork), but there's almost never a good reason you'd want to do that instead of using something like [`proc_open`](http://php.net/proc_open), which gives you much more control over the child process's file descriptors and whatnot.<|eor|><|eoss|><|endoftext|> | 21 |
lolphp | duskwuff | chfl5a8 | <|soss|><|sot|>exec returns string... wait... exec returns?<|eot|><|sost|>*Return Values: The last line from the result of the command.* [http://www.php.net/manual/en/function.exec.php]
In C, shell, perl, and ruby, exec doesn't return. The calling process is overwritten. You would use system() if you want it to return.
In PHP, system executes a command and displays the output. Exec is just like system, except it doesn't display the output.<|eost|><|sor|>PHP does have [`pcntl_exec`](http://php.net/pcntl_exec) if you want the real thing.
But it's *never* something that you actually want. Calling `execve()` in a web server, or in a FastCGI worker, will leave the new process completely dazed and confused, with a bunch of file descriptors it doesn't know what to do with, and a parent that's expecting it to get back to its normal job once it's done handling this request. You can lead up to it with [`pcntl_fork`](http://php.net/pcntl_fork), but there's almost never a good reason you'd want to do that instead of using something like [`proc_open`](http://php.net/proc_open), which gives you much more control over the child process's file descriptors and whatnot.<|eor|><|soopr|>> Calling exec() in a web server, or in a FastCGI worker, will leave the new process completely dazed and confused
You mean calling pcntl_exec() is bad right? Calling exec() is just like calling system() except it doesn't display the output.<|eoopr|><|sor|>I mean the `exec()` system call. Changed to `execve()` to be a little clearer<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | Lokaltog | 23vqcw | <|sols|><|sot|>4chan source code leak (x-post /r/programming)<|eot|><|sol|>http://pastebin.com/a45dp3Q1<|eol|><|eols|><|endoftext|> | 24 |
lolphp | catcradle5 | ch182kx | <|sols|><|sot|>4chan source code leak (x-post /r/programming)<|eot|><|sol|>http://pastebin.com/a45dp3Q1<|eol|><|sor|>To my knowledge this is an old leak posted some time in 2010. I don't think the site is currently running this code or anything like this code.
For those who are wondering why this has become news: Yesterday, 4chan's database was accessed (read-only) via SQL injection by someone poring through this source (and I think a few other old source files that I can't find) and using it to build a wordlist of directories and filenames.
He bruteforced URL paths until he found an old, forgotten about directory that had a file that was vulnerable to easy SQL injection in at least one of its parameters. He was not able to pivot his access any further but was able to authenticate as moot, post under his name, and view IPs of posts and such.
Regardless, the fact that the site was running code like this at any point after 2010 is hilarious.
You know you're going to have fun when you see
extract($_POST);
extract($_GET);
extract($_COOKIE);
in the first few lines.<|eor|><|eols|><|endoftext|> | 26 |
lolphp | milordi | ch1z4j8 | <|sols|><|sot|>4chan source code leak (x-post /r/programming)<|eot|><|sol|>http://pastebin.com/a45dp3Q1<|eol|><|sor|> $salt = "LOLLOLOLOLOLOLOLOLOLOLOLOLOLOLOL"; #this is ONLY used if the host doesn't have openssl
#I don't know a better way to get random data
I just don't have words...<|eor|><|eols|><|endoftext|> | 23 |
lolphp | David_Crockett | ch1fy8t | <|sols|><|sot|>4chan source code leak (x-post /r/programming)<|eot|><|sol|>http://pastebin.com/a45dp3Q1<|eol|><|sor|>To my knowledge this is an old leak posted some time in 2010. I don't think the site is currently running this code or anything like this code.
For those who are wondering why this has become news: Yesterday, 4chan's database was accessed (read-only) via SQL injection by someone poring through this source (and I think a few other old source files that I can't find) and using it to build a wordlist of directories and filenames.
He bruteforced URL paths until he found an old, forgotten about directory that had a file that was vulnerable to easy SQL injection in at least one of its parameters. He was not able to pivot his access any further but was able to authenticate as moot, post under his name, and view IPs of posts and such.
Regardless, the fact that the site was running code like this at any point after 2010 is hilarious.
You know you're going to have fun when you see
extract($_POST);
extract($_GET);
extract($_COOKIE);
in the first few lines.<|eor|><|sor|>> any point after 2010 is hilarious
any point after 2002...<|eor|><|eols|><|endoftext|> | 17 |
lolphp | captainramen | ch12na9 | <|sols|><|sot|>4chan source code leak (x-post /r/programming)<|eot|><|sol|>http://pastebin.com/a45dp3Q1<|eol|><|sor|>Dat SQL injection<|eor|><|eols|><|endoftext|> | 7 |
lolphp | kat5dotpostfix | ch1q6yq | <|sols|><|sot|>4chan source code leak (x-post /r/programming)<|eot|><|sol|>http://pastebin.com/a45dp3Q1<|eol|><|sor|>To my knowledge this is an old leak posted some time in 2010. I don't think the site is currently running this code or anything like this code.
For those who are wondering why this has become news: Yesterday, 4chan's database was accessed (read-only) via SQL injection by someone poring through this source (and I think a few other old source files that I can't find) and using it to build a wordlist of directories and filenames.
He bruteforced URL paths until he found an old, forgotten about directory that had a file that was vulnerable to easy SQL injection in at least one of its parameters. He was not able to pivot his access any further but was able to authenticate as moot, post under his name, and view IPs of posts and such.
Regardless, the fact that the site was running code like this at any point after 2010 is hilarious.
You know you're going to have fun when you see
extract($_POST);
extract($_GET);
extract($_COOKIE);
in the first few lines.<|eor|><|sor|>Do people read the manual?
>Warning
Do not use extract() on untrusted data, like user input (i.e. $_GET, $_FILES, etc.). If you do, for example if you want to run old code that relies on register_globals temporarily, make sure you use one of the non-overwriting flags values such as EXTR_SKIP and be aware that you should extract in the same order that's defined in variables_order within the php.ini.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | dochoncho | chb7ywg | <|sols|><|sot|>4chan source code leak (x-post /r/programming)<|eot|><|sol|>http://pastebin.com/a45dp3Q1<|eol|><|sor|>I'm surprised the code wasn't formatted to make an ASCII representation of goatse<|eor|><|eols|><|endoftext|> | 5 |
lolphp | gearvOsh | ch1ipfe | <|sols|><|sot|>4chan source code leak (x-post /r/programming)<|eot|><|sol|>http://pastebin.com/a45dp3Q1<|eol|><|sor|>Well 4chan is old, and was running old PHP4 code, so this was expected. The code base no longer looks like this.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | krinndnz | v8n4q | <|sols|><|sot|>An array that survives being overwritten<|eot|><|sol|>http://thedailywtf.com/Articles/Loose-Cat-Handling.aspx<|eol|><|eols|><|endoftext|> | 26 |
lolphp | xnhy | c52cyzz | <|sols|><|sot|>An array that survives being overwritten<|eot|><|sol|>http://thedailywtf.com/Articles/Loose-Cat-Handling.aspx<|eol|><|sor|>> The one thing I can say for php, at least it isn't javascript. Now with html5 web devs are expected to make full scale web apps using js, a language that doesn't support file includes and object orientation only through a whole lot of syntactic sugar. And it has to run on many platforms with different implementations of js. Now QA and debugging time has multiplied by an order of 10. Makes me long for the days of Flash and Actionscript... say what you want about Flash, but at least AS3 is a real language and runs relatively the same across platforms. And furthermore, say what you want about the tenets of national socialism, dude, at least it's an ethos!
-- a commenter
TRWTF is this guy. For starters, JavaScript has a really elegant object model ...<|eor|><|sor|> \|||/
(o o)
,~~~ooO~~(_)~~~~~~~~~,
| Please |
| don't feed the |
| TROLL! |
'~~~~~~~~~~~~~~ooO~~~'
|__|__|
|| ||
ooO Ooo<|eor|><|eols|><|endoftext|> | 9 |
lolphp | gatlin | c52b6ik | <|sols|><|sot|>An array that survives being overwritten<|eot|><|sol|>http://thedailywtf.com/Articles/Loose-Cat-Handling.aspx<|eol|><|sor|>> The one thing I can say for php, at least it isn't javascript. Now with html5 web devs are expected to make full scale web apps using js, a language that doesn't support file includes and object orientation only through a whole lot of syntactic sugar. And it has to run on many platforms with different implementations of js. Now QA and debugging time has multiplied by an order of 10. Makes me long for the days of Flash and Actionscript... say what you want about Flash, but at least AS3 is a real language and runs relatively the same across platforms. And furthermore, say what you want about the tenets of national socialism, dude, at least it's an ethos!
-- a commenter
TRWTF is this guy. For starters, JavaScript has a really elegant object model ...<|eor|><|eols|><|endoftext|> | 7 |
lolphp | sandsmark | udnvg | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|eols|><|endoftext|> | 25 |
lolphp | kouteiheika | c4uq8xe | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>> Tried my hand at C but pointers keep messing me up, even to this day. I have no idea why.
Let me guess - because you are a terrible programmer?<|eor|><|eols|><|endoftext|> | 43 |
lolphp | hyrulz | c4ul8ts | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>Which sentence tells me that the author is a little php fanboy and doesn't know shit about other programming languages?
>Dynamic typing
DING
>It plain works
DING DING
>Best documentation on the web
DING DING DING ^DINGDING^DINGDING
<|eor|><|eols|><|endoftext|> | 27 |
lolphp | dagbrown | c4ur6c9 | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>> Tried my hand at C but pointers keep messing me up, even to this day. I have no idea why.
Let me guess - because you are a terrible programmer?<|eor|><|sor|>That was the bit which got me giggling in advance of his actual list. Then I got to
> I wont need experts
and I knew I liked this article. For all the wrong reasons (at least as far as the author is concerned).<|eor|><|eols|><|endoftext|> | 22 |
lolphp | StrangeWill | c4unmac | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>Which sentence tells me that the author is a little php fanboy and doesn't know shit about other programming languages?
>Dynamic typing
DING
>It plain works
DING DING
>Best documentation on the web
DING DING DING ^DINGDING^DINGDING
<|eor|><|sor|>[deleted]<|eor|><|sor|>http://lmgtfy.com/?q=mysql+php
Oh look, miles of tutorials on how NOT to query a MySQL database, string concatenation everywhere.<|eor|><|eols|><|endoftext|> | 21 |
lolphp | duskwuff | c4umxtb | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>Which sentence tells me that the author is a little php fanboy and doesn't know shit about other programming languages?
>Dynamic typing
DING
>It plain works
DING DING
>Best documentation on the web
DING DING DING ^DINGDING^DINGDING
<|eor|><|sor|>[deleted]<|eor|><|sor|>Easy. Python's documentation is far better:
http://docs.python.org/release/3.2/
PHP's documentation is crap it's split up function by function, making proper comparisons and overviews limited to nonexistent, and the "comments" are full of crazy wrongness. Where there are overviews, they're often badly maintained: for instance, [their tutorial on SQL injection](http://www.php.net/manual/en/security.database.sql-injection.php) makes no mention of parameterized queries.<|eor|><|eols|><|endoftext|> | 20 |
lolphp | workman161 | c4ukkpf | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>> When it fails, it doesnt fail hard Granted, you can fail spectacularly with PHP, but it probably wont be PHPs fault. Because PHP cleans up and starts over for each request, one request will not corrupt another. Other languages need a lot of plumbing to handle that. PHP does it by default.
what kind of shitty HTTP server do you have that allows subsequent HTTP requests to be corrupted by previous ones?<|eor|><|eols|><|endoftext|> | 17 |
lolphp | sloat | c4uhrx4 | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>I honestly couldn't tell if the author was being sarcastic. Basically every point is contradictory to reality. I thought about doing a point-by-point refuting, but why bother? We all know which subreddit we're in and why it exists.<|eor|><|eols|><|endoftext|> | 17 |
lolphp | xiongchiamiov | c4utyjg | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>> Tried my hand at C but pointers keep messing me up, even to this day. I have no idea why.
Let me guess - because you are a terrible programmer?<|eor|><|sor|>When I saw that he was working for Zend, PHP began to make a lot more sense.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | InconsiderateBastard | c4uol6n | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>Which sentence tells me that the author is a little php fanboy and doesn't know shit about other programming languages?
>Dynamic typing
DING
>It plain works
DING DING
>Best documentation on the web
DING DING DING ^DINGDING^DINGDING
<|eor|><|sor|>[deleted]<|eor|><|sor|>It certainly has a lot of documentation, it's just a shame how many innacuracies you can find if you look through it closely. The PDO page says it doesn't emulate features. Then the prepared statements page explains that it will emulate prepared statements in DBs that don't have them. And, naturally, it actually emulates (or emulated? Have they fixed it?) prepared statements for everything unless you specify not to with all your calls.
If they've fixed these, I apologize, it's been a couple months since I looked at the documentation. And, even if they have, I'm sure there're plenty of other problems with their documentation to illustrate why it shouldn't be called the best.
Edit: grammar<|eor|><|eols|><|endoftext|> | 12 |
lolphp | BigRedS | c4usda6 | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>Which sentence tells me that the author is a little php fanboy and doesn't know shit about other programming languages?
>Dynamic typing
DING
>It plain works
DING DING
>Best documentation on the web
DING DING DING ^DINGDING^DINGDING
<|eor|><|sor|>[deleted]<|eor|><|sor|>Easy. Python's documentation is far better:
http://docs.python.org/release/3.2/
PHP's documentation is crap it's split up function by function, making proper comparisons and overviews limited to nonexistent, and the "comments" are full of crazy wrongness. Where there are overviews, they're often badly maintained: for instance, [their tutorial on SQL injection](http://www.php.net/manual/en/security.database.sql-injection.php) makes no mention of parameterized queries.<|eor|><|sor|>[deleted]<|eor|><|sor|>You do realise that this is one of PHP's major problems - you keep needing to check the documentation to work out which order any given function wants its argument, or where the underscores go in the function names?<|eor|><|eols|><|endoftext|> | 11 |
lolphp | Syn3rgy | c50zlz3 | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>I read this subreddit through a multi-reddit with r/programming and a bunch of others, and at first I thought this has been posted to r/programming and I was ready to downvote and mock. Then I realized where it was actually posted and it was quite fitting.
<|eor|><|sor|>I like to browse /r/lolphp+php. It's sometimes quite a challenge to tell the mocking submission from the real ones.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | xiongchiamiov | c4utxw3 | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>Which sentence tells me that the author is a little php fanboy and doesn't know shit about other programming languages?
>Dynamic typing
DING
>It plain works
DING DING
>Best documentation on the web
DING DING DING ^DINGDING^DINGDING
<|eor|><|sor|>[deleted]<|eor|><|sor|>Easy. Python's documentation is far better:
http://docs.python.org/release/3.2/
PHP's documentation is crap it's split up function by function, making proper comparisons and overviews limited to nonexistent, and the "comments" are full of crazy wrongness. Where there are overviews, they're often badly maintained: for instance, [their tutorial on SQL injection](http://www.php.net/manual/en/security.database.sql-injection.php) makes no mention of parameterized queries.<|eor|><|sor|>To add onto that, the Django docs are orgasmic.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | Rhomboid | c4uh2zv | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>I read this subreddit through a multi-reddit with r/programming and a bunch of others, and at first I thought this has been posted to r/programming and I was ready to downvote and mock. Then I realized where it was actually posted and it was quite fitting.
<|eor|><|eols|><|endoftext|> | 9 |
lolphp | workman161 | c4uo6zr | <|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>> When it fails, it doesnt fail hard Granted, you can fail spectacularly with PHP, but it probably wont be PHPs fault. Because PHP cleans up and starts over for each request, one request will not corrupt another. Other languages need a lot of plumbing to handle that. PHP does it by default.
what kind of shitty HTTP server do you have that allows subsequent HTTP requests to be corrupted by previous ones?<|eor|><|sor|>I dunno, [maybe one running PHP](https://bugs.php.net/bug.php?id=49753)?<|eor|><|sor|>The irony is strong here.<|eor|><|eols|><|endoftext|> | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.