subreddit stringclasses 7
values | author stringlengths 3 20 | id stringlengths 5 7 | content stringlengths 67 30.4k | score int64 0 140k |
|---|---|---|---|---|
lolphp | Rhomboid | clqu1mr | <|sols|><|sot|>Prepared statements in pdo, running in emulated mode (which is default), will split the query on semi colons, and execute multiple queries thus formed, allowing SQL injection attacks and was the basis on the last Drupal vulnerability.<|eot|><|sol|>http://blog.ircmaxell.com/2014/10/a-lesson-in-security.html<|eol|><|sor|>I'm not an expert on PDO, but why is PDO so crucial?
Can't I just write:
$query = "SELECT * FROM table WHERE userid = '" . $userid . "'";
...and as long as I replace all problematic characters (" ' ` \ etc.) in $userid BEFORE it is added to $query, shouldn't that make the query immune to manipulation? For example:
$userid = "' OR user != ''; DROP table;";
would turn into this if I replaced ' with `:
$userid = "` OR user != ``; DROP table;";
And this would occur BEFORE it gets placed in $query.
I mean, you may be able to still get junk data input if this is ALL you do before it hits the database, but no actual $query variable manipulation can occur. I couldn't send a command to drop a table or do something else.<|eor|><|sor|>Yeah, the problem with that approach, as /u/allthediamonds points out, is that you fight a losing battle when you have to constantly maintain a blacklist of disallowed characters. Let a well-established framework do that heavy lifting for you (hopefully approaching things from the opposite angle: whitelisting allowed characters).
Also upvoted you, because you provided a good topic for discussion, and I think your current downvotes are "zomg disagree so dum" types.<|eor|><|sor|>But if the query is written using ONLY " and ' and \, and you convert those to ``, ` and / respectively, won't that eliminate the chance of someone bypassing the purpose of the $query variable? I mean, and am I totally in the wrong here?
I'm not saying I can 100% protect against garbage data - I'm just saying I can protect against a simple query being manipulated to empty my table.<|eor|><|sor|>How does replacing backslash with forward slash accomplish anything? If you're going to do manual escaping, you have to turn `\` into `\\`, `"` into `\"`, `'` into `\'`, and possibly others, like the null byte, cr, lf, etc. Also, these rules are *different for every database*. How you safely escape a string for database A might leave you open to vulnerabilities under database B. And that's not even getting into things like multibyte character encoding vulnerabilities.
Again, people have been telling themselves that it's simple to do escaping manually for ~15 years and they've been *consistently and reliably proven wrong*.
<|eor|><|eols|><|endoftext|> | 8 |
lolphp | DoctorWaluigiTime | clqqz2e | <|sols|><|sot|>Prepared statements in pdo, running in emulated mode (which is default), will split the query on semi colons, and execute multiple queries thus formed, allowing SQL injection attacks and was the basis on the last Drupal vulnerability.<|eot|><|sol|>http://blog.ircmaxell.com/2014/10/a-lesson-in-security.html<|eol|><|sor|>I'm not an expert on PDO, but why is PDO so crucial?
Can't I just write:
$query = "SELECT * FROM table WHERE userid = '" . $userid . "'";
...and as long as I replace all problematic characters (" ' ` \ etc.) in $userid BEFORE it is added to $query, shouldn't that make the query immune to manipulation? For example:
$userid = "' OR user != ''; DROP table;";
would turn into this if I replaced ' with `:
$userid = "` OR user != ``; DROP table;";
And this would occur BEFORE it gets placed in $query.
I mean, you may be able to still get junk data input if this is ALL you do before it hits the database, but no actual $query variable manipulation can occur. I couldn't send a command to drop a table or do something else.<|eor|><|sor|>Yeah, the problem with that approach, as /u/allthediamonds points out, is that you fight a losing battle when you have to constantly maintain a blacklist of disallowed characters. Let a well-established framework do that heavy lifting for you (hopefully approaching things from the opposite angle: whitelisting allowed characters).
Also upvoted you, because you provided a good topic for discussion, and I think your current downvotes are "zomg disagree so dum" types.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | Katastic_Voyage | clqsnjj | <|sols|><|sot|>Prepared statements in pdo, running in emulated mode (which is default), will split the query on semi colons, and execute multiple queries thus formed, allowing SQL injection attacks and was the basis on the last Drupal vulnerability.<|eot|><|sol|>http://blog.ircmaxell.com/2014/10/a-lesson-in-security.html<|eol|><|sor|>I'm not an expert on PDO, but why is PDO so crucial?
Can't I just write:
$query = "SELECT * FROM table WHERE userid = '" . $userid . "'";
...and as long as I replace all problematic characters (" ' ` \ etc.) in $userid BEFORE it is added to $query, shouldn't that make the query immune to manipulation? For example:
$userid = "' OR user != ''; DROP table;";
would turn into this if I replaced ' with `:
$userid = "` OR user != ``; DROP table;";
And this would occur BEFORE it gets placed in $query.
I mean, you may be able to still get junk data input if this is ALL you do before it hits the database, but no actual $query variable manipulation can occur. I couldn't send a command to drop a table or do something else.<|eor|><|sor|>Dear Reddit, stop downvoting people just because they have a goddamn honest question.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | Rhomboid | clqrseu | <|sols|><|sot|>Prepared statements in pdo, running in emulated mode (which is default), will split the query on semi colons, and execute multiple queries thus formed, allowing SQL injection attacks and was the basis on the last Drupal vulnerability.<|eot|><|sol|>http://blog.ircmaxell.com/2014/10/a-lesson-in-security.html<|eol|><|sor|>I'm not an expert on PDO, but why is PDO so crucial?
Can't I just write:
$query = "SELECT * FROM table WHERE userid = '" . $userid . "'";
...and as long as I replace all problematic characters (" ' ` \ etc.) in $userid BEFORE it is added to $query, shouldn't that make the query immune to manipulation? For example:
$userid = "' OR user != ''; DROP table;";
would turn into this if I replaced ' with `:
$userid = "` OR user != ``; DROP table;";
And this would occur BEFORE it gets placed in $query.
I mean, you may be able to still get junk data input if this is ALL you do before it hits the database, but no actual $query variable manipulation can occur. I couldn't send a command to drop a table or do something else.<|eor|><|sor|>> and as long as I replace all problematic characters
People have been saying that to themselves for the last ~15 years. It has never turned out to be true; eventually you will mess up. Maybe there's a string that you thought you already sanitized but you really didn't. Maybe you thought you had a string that couldn't possibly contain anything but digits, but it can. Maybe a new method of defeating the escaping is discovered and you're not an expert on such things.
This is the "I don't need seatbelts, I'll just brace myself"(*) of the software development world.
(*) Yes, that was a real justification that real people gave when the government tried to mandate seat belt usage. People actively fought tooth and nail for the privilege of being needlessly mangled in accidents.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | _vec_ | cls36p9 | <|sols|><|sot|>Prepared statements in pdo, running in emulated mode (which is default), will split the query on semi colons, and execute multiple queries thus formed, allowing SQL injection attacks and was the basis on the last Drupal vulnerability.<|eot|><|sol|>http://blog.ircmaxell.com/2014/10/a-lesson-in-security.html<|eol|><|sor|>I'm not an expert on PDO, but why is PDO so crucial?
Can't I just write:
$query = "SELECT * FROM table WHERE userid = '" . $userid . "'";
...and as long as I replace all problematic characters (" ' ` \ etc.) in $userid BEFORE it is added to $query, shouldn't that make the query immune to manipulation? For example:
$userid = "' OR user != ''; DROP table;";
would turn into this if I replaced ' with `:
$userid = "` OR user != ``; DROP table;";
And this would occur BEFORE it gets placed in $query.
I mean, you may be able to still get junk data input if this is ALL you do before it hits the database, but no actual $query variable manipulation can occur. I couldn't send a command to drop a table or do something else.<|eor|><|sor|>> and as long as I replace all problematic characters
People have been saying that to themselves for the last ~15 years. It has never turned out to be true; eventually you will mess up. Maybe there's a string that you thought you already sanitized but you really didn't. Maybe you thought you had a string that couldn't possibly contain anything but digits, but it can. Maybe a new method of defeating the escaping is discovered and you're not an expert on such things.
This is the "I don't need seatbelts, I'll just brace myself"(*) of the software development world.
(*) Yes, that was a real justification that real people gave when the government tried to mandate seat belt usage. People actively fought tooth and nail for the privilege of being needlessly mangled in accidents.<|eor|><|sor|>Okay, I can understand that - this way I'm describing is not 100% foolproof. It fails if even one user-input variable isn't sanitized.
Is that the only problem then? Eventually a programmer will miss something?<|eor|><|sor|>> Is that the only problem then? Eventually a programmer will miss something?
Well, for broad enough values of "miss something", yes. The problem is the number of "something"s available to miss is larger than you think it is. For example:
* Does your escaping method know whether it's escaping a string or a number? "`0; DROP TABLE users; --`" is a perfectly valid string but a disastrous "number".
* Does your escaping method handle UTF-8 properly? There is a clever attack, for example, that expects you to insert a backslash before a quote but interprets the backslash as the last byte of the previous character, so the quote remains unescaped.
* Are you sure you're escaping correctly for the database you're currently using? MySQL expects you to escape single quotes with a backslash (i.e. "`can\'t`") whereas Postgresql expects them to be repeated (i.e. "`can''t`"). Can you guarantee that the database your app is using will never change?
And that's just off the top of my head. Even if you use it 100% correctly in your app there are still so many small database discrepencies and weird string processing edge cases that it's almost impossible to protect against all of them.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | pilif | 239fmc | <|sols|><|sot|>String? No. This looks like a number. It must be one.<|eot|><|sol|>http://codepad.org/NMc1idYX<|eol|><|eols|><|endoftext|> | 45 |
lolphp | Rhomboid | cgurouy | <|sols|><|sot|>String? No. This looks like a number. It must be one.<|eot|><|sol|>http://codepad.org/NMc1idYX<|eol|><|sor|>Oh, it's even sadder than that. Try to use a float as a key? Silently cast to integer and truncated. That might make sense if arrays were purely numerically indexed, but they're really hash maps. If you can hash a string why not hash a float? Ruby, Perl, and Python have no problem with this.
And similarly null gets silently converted to the empty string when used as a key, and booleans get silently converted to integers. There's no consistency at all.
<|eor|><|eols|><|endoftext|> | 25 |
lolphp | pilif | cgura3a | <|sols|><|sot|>String? No. This looks like a number. It must be one.<|eot|><|sol|>http://codepad.org/NMc1idYX<|eol|><|soopr|>This pisses me off endlessly as silent conversions of strings into number is working against any use of the === operator.
In this particular case, it's impossible to have a string that looks like a number as an array key. If it looks like a number, it gets converted and thus breaks any uses of the === operator later on.
Take a string, add it to an array as a key, take that key, compare with the original string. Won't pass ===<|eoopr|><|eols|><|endoftext|> | 16 |
lolphp | HelloAnnyong | cgyh3gy | <|sols|><|sot|>String? No. This looks like a number. It must be one.<|eot|><|sol|>http://codepad.org/NMc1idYX<|eol|><|sor|>Oh man, this behaviour leads to an entire class of bugs that you will never see in development, but will only appear in production.
PHP's insistence on coercing strings to integers without telling you particularly gets you when you're writing code that deals with hashes (as in MD5s or SHAs). Strings that are *almost* always hexadecimal, but occasionally are decimal.
Use those strings as array keys and your keys will almost always be strings, but occasionally (when you have the rare hash that has no letters) you will end up with an integer key. Causing some comparison somewhere in your code to fail when it shouldn't.
**Even more maddening is that this behaviour depends not only on the length of the number but also on the architecture of the machine it's running on.** For real.
Take a look. Here's some code on codepad (presumably running a 32-bit version of PHP): http://codepad.org/pwEC68w8
Here's the result:
Starting with the string 11111111
Are they equal using ==: yes
Are they equal using ===: no
Starting with the string 11111111111111
Are they equal using ==: yes
Are they equal using ===: yes
Starting with the string 111111111111111111111111111111111111
Are they equal using ==: yes
Are they equal using ===: yes
Running the same code on [php repl](http://phpepl.cloudcontrolled.com/) (which is running a 64-bit version) results in this:
Starting with the string 11111111
Are they equal using ==: yes
Are they equal using ===: no
Starting with the string 11111111111111
Are they equal using ==: yes
Are they equal using ===: no
Starting with the string 111111111111111111111111111111111111
Are they equal using ==: yes
Are they equal using ===: yes
<|eor|><|eols|><|endoftext|> | 13 |
lolphp | barubary | cgwrcs7 | <|sols|><|sot|>String? No. This looks like a number. It must be one.<|eot|><|sol|>http://codepad.org/NMc1idYX<|eol|><|sor|>Oh, it's even sadder than that. Try to use a float as a key? Silently cast to integer and truncated. That might make sense if arrays were purely numerically indexed, but they're really hash maps. If you can hash a string why not hash a float? Ruby, Perl, and Python have no problem with this.
And similarly null gets silently converted to the empty string when used as a key, and booleans get silently converted to integers. There's no consistency at all.
<|eor|><|sor|>You should never compare a float for equality directly, without epsilon.
Therefore it's sensible to forbid float keys in a hash.<|eor|><|sor|>But PHP doesn't forbid float keys in a hash, it silently corrupts their values instead.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | edave64 | cgv0bt9 | <|sols|><|sot|>String? No. This looks like a number. It must be one.<|eot|><|sol|>http://codepad.org/NMc1idYX<|eol|><|sor|>Oh, it's even sadder than that. Try to use a float as a key? Silently cast to integer and truncated. That might make sense if arrays were purely numerically indexed, but they're really hash maps. If you can hash a string why not hash a float? Ruby, Perl, and Python have no problem with this.
And similarly null gets silently converted to the empty string when used as a key, and booleans get silently converted to integers. There's no consistency at all.
<|eor|><|sor|>JavaScript converts every key of every object automatically into strings. But at least it does it consistently.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | huf | cgus0vj | <|sols|><|sot|>String? No. This looks like a number. It must be one.<|eot|><|sol|>http://codepad.org/NMc1idYX<|eol|><|soopr|>This pisses me off endlessly as silent conversions of strings into number is working against any use of the === operator.
In this particular case, it's impossible to have a string that looks like a number as an array key. If it looks like a number, it gets converted and thus breaks any uses of the === operator later on.
Take a string, add it to an array as a key, take that key, compare with the original string. Won't pass ===<|eoopr|><|sor|>well...... there *is* a way...
php -r '$x = new stdclass; $x->{"123"} = 2; $x = (array)$x; list($x) = array_keys($x); var_dump($x);'<|eor|><|eols|><|endoftext|> | 7 |
lolphp | Rhomboid | cgwkw9p | <|sols|><|sot|>String? No. This looks like a number. It must be one.<|eot|><|sol|>http://codepad.org/NMc1idYX<|eol|><|sor|>Oh, it's even sadder than that. Try to use a float as a key? Silently cast to integer and truncated. That might make sense if arrays were purely numerically indexed, but they're really hash maps. If you can hash a string why not hash a float? Ruby, Perl, and Python have no problem with this.
And similarly null gets silently converted to the empty string when used as a key, and booleans get silently converted to integers. There's no consistency at all.
<|eor|><|sor|>You should never compare a float for equality directly, without epsilon.
Therefore it's sensible to forbid float keys in a hash.<|eor|><|sor|>It's perfectly fine to compare floating point values for equality when you're working with exactly representable values.
And as I said, none of the other major dynamic scripting languages seem to have found it necessary to forbid floating point values as hash keys.
Edit: also, hashes are necessarily always used for lookups. You might want to use them for things like removing duplicates or other set-like operations.<|eor|><|sor|>And when you are working just with exactly representable values? One example might be computing powers of 2, but in practice, there are no such applications.<|eor|><|sor|>Just off the top of my head:
- shoe sizes (8, 8.5, 9, 9.5)
- waistline sizes (33, 33.5, 34)
- paper dimensions (8.5 x 11, 8.5 x 14, 4.25 x 6.75)
- cooking amounts (1.75, 3.125, 4.25)
- wrench sizes (.9375 (=15/16), 0.875 (=7/8))
...and so on. All of the above are exactly representable in binary floating point, and there is no possibility of roundoff error.
<|eor|><|sor|>Right. However, what is the point of having those in a hash?
I just wanted to say that having floats as hash keys is really rarely needed feature, therefore we should not make fun of PHP for that.
They are converted to strings and things work regardless.<|eor|><|sor|>Say you're dealing with a set of product data, and you have something like `{model_x: {size: 8.5, ...}, 'model_y': {size: 9.5, ...}}`. You might want to invert that to get all the models with a given size: `{8.5: ['model_x', 'model_z', ...], 9.5: ['model_y`, ...]}`.
> They are converted to strings and things work regardless.
No they're not, PHP casts them to integers and truncates them! That's what's so baffling and stupefying. Converting to a string would be at least justifiable.
<|eor|><|eols|><|endoftext|> | 6 |
lolphp | postmodest | cgvh8ey | <|sols|><|sot|>String? No. This looks like a number. It must be one.<|eot|><|sol|>http://codepad.org/NMc1idYX<|eol|><|sor|>some day they'll make hash() "a language construct" and all the Perl people will look at them and say "You're all fucking retards."<|eor|><|sor|>> all the Perl people will look at them and say "You're all fucking retards."
implying that isn't already happening<|eor|><|sor|>Well, as a Perl dude working PHP full-time, it's more the part where they make the array syntax "array()". And then give in and make it "[]" while doing silly things like $hash = ["foo"=>"bar"]; because "reasons". <|eor|><|eols|><|endoftext|> | 5 |
lolphp | barubary | 1efmol | <|soss|><|sot|>I love JSON; it's so easy!<|eot|><|sost|> % php -r 'var_dump(json_decode("true"));'
bool(true)
% php -r 'var_dump(json_decode("tRue"));'
bool(true)
% php -r 'var_dump(json_decode("true "));'
NULL
% php -r 'var_dump(json_decode("[true ] "));'
array(1) {
[0]=>
bool(true)
}
% php -r 'var_dump(json_decode("[tRue]"));'
NULL
<|eost|><|eoss|><|endoftext|> | 43 |
lolphp | tdammers | c9zsqbv | <|soss|><|sot|>I love JSON; it's so easy!<|eot|><|sost|> % php -r 'var_dump(json_decode("true"));'
bool(true)
% php -r 'var_dump(json_decode("tRue"));'
bool(true)
% php -r 'var_dump(json_decode("true "));'
NULL
% php -r 'var_dump(json_decode("[true ] "));'
array(1) {
[0]=>
bool(true)
}
% php -r 'var_dump(json_decode("[tRue]"));'
NULL
<|eost|><|sor|>At first, I thought it would make sense in some weird way, but then I read the documentation. The strings "true", "false", and "null" are apparently special-cased to work as top-level constructs, and as such, they are handled case-insensitively. Inside the list, though, they are handled by the actual parser, which *is* case sensitive (just like the standard mandates).
This has little to do with the JSON specification, which says that these keywords have to be lower-case, and they appear to be special-cased at the very top level (probably something like `if (stricmp(json, "true") == 0) return PHP_TRUE; /* ... */`, which would also explain why the extra whitespace breaks the parser.
But hey, at least it's fast, right?<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | wwwwolf | ca143me | <|soss|><|sot|>I love JSON; it's so easy!<|eot|><|sost|> % php -r 'var_dump(json_decode("true"));'
bool(true)
% php -r 'var_dump(json_decode("tRue"));'
bool(true)
% php -r 'var_dump(json_decode("true "));'
NULL
% php -r 'var_dump(json_decode("[true ] "));'
array(1) {
[0]=>
bool(true)
}
% php -r 'var_dump(json_decode("[tRue]"));'
NULL
<|eost|><|sor|>At first, I thought it would make sense in some weird way, but then I read the documentation. The strings "true", "false", and "null" are apparently special-cased to work as top-level constructs, and as such, they are handled case-insensitively. Inside the list, though, they are handled by the actual parser, which *is* case sensitive (just like the standard mandates).
This has little to do with the JSON specification, which says that these keywords have to be lower-case, and they appear to be special-cased at the very top level (probably something like `if (stricmp(json, "true") == 0) return PHP_TRUE; /* ... */`, which would also explain why the extra whitespace breaks the parser.
But hey, at least it's fast, right?<|eor|><|sor|>Fascinating. RFC 4627 says "A JSON text is a serialized object or array." Ruby's json library will throw a parse error if it the top-level item isn't a hash or an array. And yep, it's case sensitive:
irb> JSON.parse('true')
JSON::ParserError: 746: unexpected token at 'true'
...
irb> JSON.parse('[true]')
=> [true]
irb> JSON.parse('[tRuE]')
JSON::ParserError: 387: unexpected token at 'tRuE]'
...
Firefox's JavaScript engine will happily parse top-level items though:
> JSON.parse("true");
true
> JSON.parse("[true]");
[true]
> JSON.parse("tRuE");
SyntaxError: JSON.parse: unexpected keyword
But it also allows other kinds of things at top level:
> JSON.parse("\"hello world\"");
"hello world"
So I guess that if you write a parser that *does* accept stuff other than arrays and hashes at top level, you should at least do that consistently. =)<|eor|><|eoss|><|endoftext|> | 9 |
lolphp | notwolverine | ca15bti | <|soss|><|sot|>I love JSON; it's so easy!<|eot|><|sost|> % php -r 'var_dump(json_decode("true"));'
bool(true)
% php -r 'var_dump(json_decode("tRue"));'
bool(true)
% php -r 'var_dump(json_decode("true "));'
NULL
% php -r 'var_dump(json_decode("[true ] "));'
array(1) {
[0]=>
bool(true)
}
% php -r 'var_dump(json_decode("[tRue]"));'
NULL
<|eost|><|sor|>I actually wrote up a bug report about this, seeing as no one else did. It will be interesting to see how they respond :)<|eor|><|sor|>Link?<|eor|><|sor|>https://bugs.php.net/bug.php?id=64874
No response yet, though<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | iheartrms | 9occ0x | <|sols|><|sot|>Not sure if LOL but seems relevant: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks | ZDNet<|eot|><|sol|>https://www.zdnet.com/article/around-62-of-all-internet-sites-will-run-an-unsupported-php-version-in-10-weeks/<|eol|><|eols|><|endoftext|> | 39 |
lolphp | BufferUnderpants | e7t89e3 | <|sols|><|sot|>Not sure if LOL but seems relevant: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks | ZDNet<|eot|><|sol|>https://www.zdnet.com/article/around-62-of-all-internet-sites-will-run-an-unsupported-php-version-in-10-weeks/<|eol|><|sor|>That's what elitists don't understand. You can FTP shitcode to a Pentium IV shared host, running a PHP version full of security holes, and get immediate results. This is something that is desirable for beginner programmers.<|eor|><|eols|><|endoftext|> | 18 |
lolphp | BufferUnderpants | e7tlf5r | <|sols|><|sot|>Not sure if LOL but seems relevant: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks | ZDNet<|eot|><|sol|>https://www.zdnet.com/article/around-62-of-all-internet-sites-will-run-an-unsupported-php-version-in-10-weeks/<|eol|><|sor|>That's what elitists don't understand. You can FTP shitcode to a Pentium IV shared host, running a PHP version full of security holes, and get immediate results. This is something that is desirable for beginner programmers.<|eor|><|sor|>What are you trying to say?<|eor|><|sor|>I'm trying to say that _lolphp_<|eor|><|eols|><|endoftext|> | 13 |
lolphp | girst | e7w5p8m | <|sols|><|sot|>Not sure if LOL but seems relevant: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks | ZDNet<|eot|><|sol|>https://www.zdnet.com/article/around-62-of-all-internet-sites-will-run-an-unsupported-php-version-in-10-weeks/<|eol|><|sor|>5.6? pffft, amateurs!
>`Apache/2.0.59easyTECC/2.0 (Unix) PHP/4.4.1 mod_perl/2.0.3 Perl/v5.8.5 Server at www.dietiwag.at Port 80`<|eor|><|eols|><|endoftext|> | 12 |
lolphp | walterbanana | e7tg2vc | <|sols|><|sot|>Not sure if LOL but seems relevant: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks | ZDNet<|eot|><|sol|>https://www.zdnet.com/article/around-62-of-all-internet-sites-will-run-an-unsupported-php-version-in-10-weeks/<|eol|><|sor|>Distributions will supply security updates for a while longer, though.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | walterbanana | e7u01m2 | <|sols|><|sot|>Not sure if LOL but seems relevant: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks | ZDNet<|eot|><|sol|>https://www.zdnet.com/article/around-62-of-all-internet-sites-will-run-an-unsupported-php-version-in-10-weeks/<|eol|><|sor|>Distributions will supply security updates for a while longer, though.<|eor|><|soopr|>Where will those security updates be coming from if upstream won't be producing them anymore? Will each distro write their own? <|eoopr|><|sor|>No, usually Red Hat fixes the issues and everybody else uses their fix. Sometimes Canonical or the Debian community are faster. PHP is open source software, so anyone with the skills to do it can solve security issues.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | Branan | e7urj87 | <|sols|><|sot|>Not sure if LOL but seems relevant: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks | ZDNet<|eot|><|sol|>https://www.zdnet.com/article/around-62-of-all-internet-sites-will-run-an-unsupported-php-version-in-10-weeks/<|eol|><|sor|>Distributions will supply security updates for a while longer, though.<|eor|><|soopr|>Where will those security updates be coming from if upstream won't be producing them anymore? Will each distro write their own? <|eoopr|><|sor|>No, usually Red Hat fixes the issues and everybody else uses their fix. Sometimes Canonical or the Debian community are faster. PHP is open source software, so anyone with the skills to do it can solve security issues.<|eor|><|sor|>i'm not familiar with the internals of OSS and Linux distributions, but I don't understand why they should patch PHP. PHP is not part of Linux. Having a specific PHP version on a linux release seem archaic to me. It's something that doesn't happen in node or Ruby, and even PHP teams use PPAs or containers today with a newer version of PHP<|eor|><|sor|>These Linux distributions are stable releases with long support windows. A stable distribution tries to ensure that your system still works in exactly the same way as yesterday by shipping a set of packages and only doing security updates for them. This is a big deal for servers and workstations. New versions can cause issues with backwards compatibility or introduce new bugs.
Debian and Ubuntu LTS releases get security updates for 5 years, Redhat for 10 years. This includes software like Ruby and PHP. That is why PHP 5 will be supported a while longer on some of the releases from 2+ years ago. The software being open source makes these distributions able to do this. In case of Redhat people are even paying for it.
PPAs are a bad idea on a server, they will 404 before the support on your distribution ends and you have no garantees of any kind.<|eor|><|sor|>thx for explaning. i get it that it's really stable, I just wonder if a lot of people care about stability to that extent. Most developers like new things and using PHP5 is not attractive in any way. I also imagine there's a lot of people who still rely on PHP 4, so without real numbers we won't get to any conclusion. <|eor|><|sor|>Developers that like new things haven't seen enough new things break yet. There's a huge market for known, stable software<|eor|><|eols|><|endoftext|> | 9 |
lolphp | polish_niceguy | e9cm7wf | <|sols|><|sot|>Not sure if LOL but seems relevant: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks | ZDNet<|eot|><|sol|>https://www.zdnet.com/article/around-62-of-all-internet-sites-will-run-an-unsupported-php-version-in-10-weeks/<|eol|><|sor|>5.6? pffft, amateurs!
>`Apache/2.0.59easyTECC/2.0 (Unix) PHP/4.4.1 mod_perl/2.0.3 Perl/v5.8.5 Server at www.dietiwag.at Port 80`<|eor|><|sor|>*cries in legacy*<|eor|><|eols|><|endoftext|> | 7 |
lolphp | walterbanana | e7u6u27 | <|sols|><|sot|>Not sure if LOL but seems relevant: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks | ZDNet<|eot|><|sol|>https://www.zdnet.com/article/around-62-of-all-internet-sites-will-run-an-unsupported-php-version-in-10-weeks/<|eol|><|sor|>Distributions will supply security updates for a while longer, though.<|eor|><|soopr|>Where will those security updates be coming from if upstream won't be producing them anymore? Will each distro write their own? <|eoopr|><|sor|>No, usually Red Hat fixes the issues and everybody else uses their fix. Sometimes Canonical or the Debian community are faster. PHP is open source software, so anyone with the skills to do it can solve security issues.<|eor|><|sor|>i'm not familiar with the internals of OSS and Linux distributions, but I don't understand why they should patch PHP. PHP is not part of Linux. Having a specific PHP version on a linux release seem archaic to me. It's something that doesn't happen in node or Ruby, and even PHP teams use PPAs or containers today with a newer version of PHP<|eor|><|sor|>These Linux distributions are stable releases with long support windows. A stable distribution tries to ensure that your system still works in exactly the same way as yesterday by shipping a set of packages and only doing security updates for them. This is a big deal for servers and workstations. New versions can cause issues with backwards compatibility or introduce new bugs.
Debian and Ubuntu LTS releases get security updates for 5 years, Redhat for 10 years. This includes software like Ruby and PHP. That is why PHP 5 will be supported a while longer on some of the releases from 2+ years ago. The software being open source makes these distributions able to do this. In case of Redhat people are even paying for it.
PPAs are a bad idea on a server, they will 404 before the support on your distribution ends and you have no garantees of any kind.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | guy99882 | e7tb0mn | <|sols|><|sot|>Not sure if LOL but seems relevant: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks | ZDNet<|eot|><|sol|>https://www.zdnet.com/article/around-62-of-all-internet-sites-will-run-an-unsupported-php-version-in-10-weeks/<|eol|><|sor|>That's what elitists don't understand. You can FTP shitcode to a Pentium IV shared host, running a PHP version full of security holes, and get immediate results. This is something that is desirable for beginner programmers.<|eor|><|sor|>What are you trying to say?<|eor|><|eols|><|endoftext|> | 5 |
lolphp | SjaakRake | 7yxt1i | <|sols|><|sot|>After thorough delibiration and review we've decided to deprecate this. Oh, wait, never mind.<|eot|><|sol|>http://php.net/manual/en/function.is-a.php#refsect1-function.is-a-changelog<|eol|><|eols|><|endoftext|> | 41 |
lolphp | maweki | dul563w | <|sols|><|sot|>After thorough delibiration and review we've decided to deprecate this. Oh, wait, never mind.<|eot|><|sol|>http://php.net/manual/en/function.is-a.php#refsect1-function.is-a-changelog<|eol|><|sor|>The first comment is gold:
> Whether this change is considered a bug and whether it will be reverted or kept in future versions is yet to be determined, but nevertheless it is how it is, for now...<|eor|><|eols|><|endoftext|> | 15 |
lolphp | creativeMan | 7isg11 | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|eols|><|endoftext|> | 41 |
lolphp | creativeMan | dr1b7eg | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|sor|>This demonstrates very limited understanding. I can tell you're new to PHP. Welcome.<|eor|><|soopr|>I'll admit I'm new to PHP. Not to programming though. This I believe will cause me a lot of confusion in the future.<|eoopr|><|eols|><|endoftext|> | 22 |
lolphp | PM_TACOS | dr1g8fm | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|sor|>This demonstrates very limited understanding. I can tell you're new to PHP. Welcome.<|eor|><|soopr|>I'll admit I'm new to PHP. Not to programming though. This I believe will cause me a lot of confusion in the future.<|eoopr|><|sor|>It won't.<|eor|><|sor|>Mind to explain why it does not echo 0?<|eor|><|sor|>* `(string)true === "1";`
* `(string)false === "";`
If you really wanted it to be cast to `"0"` you would do `(string)(int)false`.<|eor|><|sor|>But I dont see the reason why you should do this.
Either you say you can convert bool to string, or you say you cant. But why does one work as you might expect, but the other one does not?<|eor|><|sor|>PHP used to be for enriching HTML, where it could be desirable to echo nothing if a variable is set to false by earlier logic.
Edit: for debugging save yourself some pain and use var_dump.<|eor|><|eols|><|endoftext|> | 16 |
lolphp | creativeMan | dr12hxu | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|soopr|>0 is false though.
if(0) echo "zero";<|eoopr|><|eols|><|endoftext|> | 12 |
lolphp | Joniator | dr2yi3k | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|sor|>This demonstrates very limited understanding. I can tell you're new to PHP. Welcome.<|eor|><|soopr|>I'll admit I'm new to PHP. Not to programming though. This I believe will cause me a lot of confusion in the future.<|eoopr|><|sor|>It won't.<|eor|><|sor|>Mind to explain why it does not echo 0?<|eor|><|sor|>* `(string)true === "1";`
* `(string)false === "";`
If you really wanted it to be cast to `"0"` you would do `(string)(int)false`.<|eor|><|sor|>But I dont see the reason why you should do this.
Either you say you can convert bool to string, or you say you cant. But why does one work as you might expect, but the other one does not?<|eor|><|sor|>Because you created a story in your head about what should be expected and you place that burden of expectation on the language. Why do you expect `(string)true` to be `"1"`? Why shouldn't `(string)true` be `"true"`, or for that matter, any other value? You are not the language designer so you do not get to make these decisions and if you get upset about that you should design your own language. If you insist on using other peoples' languages you must learn how they work instead of assuming how they work.<|eor|><|sor|>The story in my head is the story of consitent design.
If you say bool to string gives an "1" and "0" back, great.
if you say bool to string give back "true" and false", awesome
If you say bool to string errors or gives back emptystring. Well, okay? Its your language.
But to randomly mix returning "1" and returning emptystring without any other reasoning than "Why not, just learn how it works or use something else" is not really a good decision.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | the_alias_of_andrea | dr1xcw9 | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|sor|>It's weird to me that `false` and `null`'s string values are both `''`. `''` makes sense for the latter perhaps, but shouldn't the former be `'0'` to contrast? I mean, `'0'` is falsey in PHP! It's specifically special-cased!<|eor|><|eols|><|endoftext|> | 10 |
lolphp | the_alias_of_andrea | dr3457m | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|sor|>It's weird to me that `false` and `null`'s string values are both `''`. `''` makes sense for the latter perhaps, but shouldn't the former be `'0'` to contrast? I mean, `'0'` is falsey in PHP! It's specifically special-cased!<|eor|><|sor|>If you train developers to assume 0 is false, outputting 0 treats it as an int and it could be true (strpos), if you have "nothing" then it trains you to always think that "nothing" is false as 0 is not always false.<|eor|><|sor|>what<|eor|><|eols|><|endoftext|> | 6 |
lolphp | vekien | dr3cksq | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|sor|>It's weird to me that `false` and `null`'s string values are both `''`. `''` makes sense for the latter perhaps, but shouldn't the former be `'0'` to contrast? I mean, `'0'` is falsey in PHP! It's specifically special-cased!<|eor|><|sor|>If you train developers to assume 0 is false, outputting 0 treats it as an int and it could be true (strpos), if you have "nothing" then it trains you to always think that "nothing" is false as 0 is not always false.<|eor|><|sor|>what<|eor|><|sor|>0 is not always false, a string position of 0 is valid. If you var_dump(false) and get 0 it would be the same as var_dump(0).
As a developer, if you assume the visual queue of 0 means that the data is false, it can lead to incorrectly assuming methods that do return 0 are also "false".
Basically: 0 != false in **all** situations, '' (aka nothing) = false in **all** situations, unless I am not remembering an internal function that can provide "nothing" for a valid state?<|eor|><|eols|><|endoftext|> | 6 |
lolphp | vekien | dr2w92c | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|soopr|>I'll admit I'm new to PHP. Not to programming though. This I believe will cause me a lot of confusion in the future.<|eoopr|><|sor|>It won't.<|eor|><|sor|>Mind to explain why it does not echo 0?<|eor|><|sor|>* `(string)true === "1";`
* `(string)false === "";`
If you really wanted it to be cast to `"0"` you would do `(string)(int)false`.<|eor|><|sor|>But I dont see the reason why you should do this.
Either you say you can convert bool to string, or you say you cant. But why does one work as you might expect, but the other one does not?<|eor|><|sor|>PHP used to be for enriching HTML, where it could be desirable to echo nothing if a variable is set to false by earlier logic.
Edit: for debugging save yourself some pain and use var_dump.<|eor|><|sor|>I kinda get that point, but that is nothing that an if-clause couldn't fix, and you would not want to print out 1 if something is true anyways, but replace it with something meaningful to the user.<|eor|><|sor|>That is kind of the point though
$user = false;
if ($loggedIn) {
$user = 'YourName';
}
in your php file:
<div class="header">
<?=$user;?>
</div>
This was kind of common place in the very olden days of PHP. A string is valid, thus true, the "false" would just show nothing, instead of showing 0.
It's just a qwerk you get used to and in my decade of PHP I've never had it be an issue, it might catch you out in things like *strpos* where 0 is valid and not a "false" value.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | Joniator | dr3g20d | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|sor|>It won't.<|eor|><|sor|>Mind to explain why it does not echo 0?<|eor|><|sor|>* `(string)true === "1";`
* `(string)false === "";`
If you really wanted it to be cast to `"0"` you would do `(string)(int)false`.<|eor|><|sor|>But I dont see the reason why you should do this.
Either you say you can convert bool to string, or you say you cant. But why does one work as you might expect, but the other one does not?<|eor|><|sor|>Because you created a story in your head about what should be expected and you place that burden of expectation on the language. Why do you expect `(string)true` to be `"1"`? Why shouldn't `(string)true` be `"true"`, or for that matter, any other value? You are not the language designer so you do not get to make these decisions and if you get upset about that you should design your own language. If you insist on using other peoples' languages you must learn how they work instead of assuming how they work.<|eor|><|sor|>The story in my head is the story of consitent design.
If you say bool to string gives an "1" and "0" back, great.
if you say bool to string give back "true" and false", awesome
If you say bool to string errors or gives back emptystring. Well, okay? Its your language.
But to randomly mix returning "1" and returning emptystring without any other reasoning than "Why not, just learn how it works or use something else" is not really a good decision.<|eor|><|sor|>I don't really agree because it isn't a consistent result (in PHP..) when you do 1/0 = true/false
You're trying to put a binary switch on 1/0 meaning true/false respectively, however 0 is not always false and shouldn't be seen as such, conditioning for it is not good design.
I think of it as "has something"/"has nothing".
1 = I have 1 of something = true
0 = I have 0 of something = false
0 is "nothing", so "nothing" comes back, your empty string. There is nothing to show, it's nothing. Maybe I've trained myself over the past decade, brainwashed :D<|eor|><|sor|> "I have a book"
"I don't have a book"
"I have 1 book"
"I have 0 books"
Those are consistent for me
"I have 1 book" and
"I don't have a book"
may be gramatically correct to, but doesn't really fit in a pattern, it's just not the obvious way for me<|eor|><|eols|><|endoftext|> | 6 |
lolphp | vekien | dr2wbap | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|sor|>It's weird to me that `false` and `null`'s string values are both `''`. `''` makes sense for the latter perhaps, but shouldn't the former be `'0'` to contrast? I mean, `'0'` is falsey in PHP! It's specifically special-cased!<|eor|><|sor|>If you train developers to assume 0 is false, outputting 0 treats it as an int and it could be true (strpos), if you have "nothing" then it trains you to always think that "nothing" is false as 0 is not always false.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | vekien | dr3skaa | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|sor|>It's weird to me that `false` and `null`'s string values are both `''`. `''` makes sense for the latter perhaps, but shouldn't the former be `'0'` to contrast? I mean, `'0'` is falsey in PHP! It's specifically special-cased!<|eor|><|sor|>If you train developers to assume 0 is false, outputting 0 treats it as an int and it could be true (strpos), if you have "nothing" then it trains you to always think that "nothing" is false as 0 is not always false.<|eor|><|sor|>what<|eor|><|sor|>0 is not always false, a string position of 0 is valid. If you var_dump(false) and get 0 it would be the same as var_dump(0).
As a developer, if you assume the visual queue of 0 means that the data is false, it can lead to incorrectly assuming methods that do return 0 are also "false".
Basically: 0 != false in **all** situations, '' (aka nothing) = false in **all** situations, unless I am not remembering an internal function that can provide "nothing" for a valid state?<|eor|><|sor|>You seem to have an interesting understanding of the word false. `0` is a falsey value in PHP: `0 == false`. Sure, a function returning `0` is not the same as it returning `false`, but that's not relevant here.<|eor|><|sor|>> but that's not relevant here
Except it is because everyone is talking about why is False not displayed as 0, there was a design choice. A design choice is made **purely** based on the authors vision and understanding.
Very relevant.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | Joniator | dr1hcf3 | <|sols|><|sot|>True is 1. False is not 0.<|eot|><|sol|>https://3v4l.org/gt31C<|eol|><|sor|>This demonstrates very limited understanding. I can tell you're new to PHP. Welcome.<|eor|><|soopr|>I'll admit I'm new to PHP. Not to programming though. This I believe will cause me a lot of confusion in the future.<|eoopr|><|sor|>It won't.<|eor|><|sor|>Mind to explain why it does not echo 0?<|eor|><|sor|>* `(string)true === "1";`
* `(string)false === "";`
If you really wanted it to be cast to `"0"` you would do `(string)(int)false`.<|eor|><|sor|>But I dont see the reason why you should do this.
Either you say you can convert bool to string, or you say you cant. But why does one work as you might expect, but the other one does not?<|eor|><|sor|>PHP used to be for enriching HTML, where it could be desirable to echo nothing if a variable is set to false by earlier logic.
Edit: for debugging save yourself some pain and use var_dump.<|eor|><|sor|>I kinda get that point, but that is nothing that an if-clause couldn't fix, and you would not want to print out 1 if something is true anyways, but replace it with something meaningful to the user.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | ZugNachPankow | 5kkpsl | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|eols|><|endoftext|> | 44 |
lolphp | mcilrain | dbp0dcy | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>Inb4 `openssl_real_public_encrypt`.<|eor|><|eols|><|endoftext|> | 40 |
lolphp | polish_niceguy | dbp40wo | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>Inb4 `openssl_real_public_encrypt`.<|eor|><|sor|>Inb4 "we can't change the defaults as it will break legacy code"<|eor|><|eols|><|endoftext|> | 28 |
lolphp | binwiederhier | dbp49ft | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>The title of this post and the article are both a bit click-bait-y. The title makes it seem like PHP and its libraries are unsafe to use, when in fact the only complaint the author makes is about one PHP function with an insecure default (rightfully so, but hard to change between versions).
Crypto primitives need to be understood thoroughly to be able to use them properly - regardless of the language. If I dont know that I shouldn't use PKCS1 or ECB, well, maybe I should read a crypto book or take a course on Coursera (can recommend!). That is in no way PHP's fault though...
The summary of the article is also very strange and tbh simply wrong: "don't use RSA", really?<|eor|><|eols|><|endoftext|> | 18 |
lolphp | ZugNachPankow | dbp0mnt | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>Inb4 `openssl_real_public_encrypt`.<|eor|><|soopr|>`openSslRealPubEncr`, FTFY<|eoopr|><|eols|><|endoftext|> | 13 |
lolphp | ZugNachPankow | dbp4jnn | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>The title of this post and the article are both a bit click-bait-y. The title makes it seem like PHP and its libraries are unsafe to use, when in fact the only complaint the author makes is about one PHP function with an insecure default (rightfully so, but hard to change between versions).
Crypto primitives need to be understood thoroughly to be able to use them properly - regardless of the language. If I dont know that I shouldn't use PKCS1 or ECB, well, maybe I should read a crypto book or take a course on Coursera (can recommend!). That is in no way PHP's fault though...
The summary of the article is also very strange and tbh simply wrong: "don't use RSA", really?<|eor|><|soopr|>I'll agree that the title was rather clickbaity, but it brings up an interesting point - many important players in the PHP ecosystem, notably Zend/Crypto, don't use a safe padding:
>Zend\Crypt didn't
>Sikker (PHP security library) didn't
>Pikirasa (PHP cryptography library) didn't
>Minds (social network allegedly backed by "Anonymous") didn't
The same is also true of "Don't use RSA" - it is an exaggeration, given the current state of RSA - but he does have a point, elliptic curve crypto is to be preferred if possible.<|eoopr|><|eols|><|endoftext|> | 12 |
lolphp | edave64 | dbq7kfp | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>Inb4 `openssl_real_public_encrypt`.<|eor|><|sor|>FYI, that's the function name because the PHP library just used the same function name as MySQL did.
http://dev.mysql.com/doc/refman/8.0/en/mysql-real-escape-string.html
It's more of a lolmysql<|eor|><|sor|>No, it's just a lolmysql too. The lolphp is having such ridiculously thin API wrapper.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | hylje | dbsf6ie | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>Inb4 `openssl_real_public_encrypt`.<|eor|><|sor|>FYI, that's the function name because the PHP library just used the same function name as MySQL did.
http://dev.mysql.com/doc/refman/8.0/en/mysql-real-escape-string.html
It's more of a lolmysql<|eor|><|sor|>This function is flawed. Please use `mysql_real_escape_string_quote` instead.
http://dev.mysql.com/doc/refman/8.0/en/mysql-real-escape-string-quote.html<|eor|><|eols|><|endoftext|> | 10 |
lolphp | nikomo | dbpvjv6 | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>Inb4 `openssl_real_public_encrypt`.<|eor|><|sor|>FYI, that's the function name because the PHP library just used the same function name as MySQL did.
http://dev.mysql.com/doc/refman/8.0/en/mysql-real-escape-string.html
It's more of a lolmysql<|eor|><|eols|><|endoftext|> | 8 |
lolphp | DeeSnow97 | dbpr9ds | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>The title of this post and the article are both a bit click-bait-y. The title makes it seem like PHP and its libraries are unsafe to use, when in fact the only complaint the author makes is about one PHP function with an insecure default (rightfully so, but hard to change between versions).
Crypto primitives need to be understood thoroughly to be able to use them properly - regardless of the language. If I dont know that I shouldn't use PKCS1 or ECB, well, maybe I should read a crypto book or take a course on Coursera (can recommend!). That is in no way PHP's fault though...
The summary of the article is also very strange and tbh simply wrong: "don't use RSA", really?<|eor|><|sor|>Don't use RSA. No, seriously. Curve25519 as a key exchange, and then AES-256-CTR or Salsa20 does a much better job. If you need to sign stuff, Ed25519 also exists. These algorithms are much faster, use compact keys, they are much more secure than RSA, and also you won't run into the mistake of encrypting stuff with a public-key algorithm (because you really don't need to).<|eor|><|eols|><|endoftext|> | 6 |
lolphp | c_o_r_b_a | dbq64mh | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>\> 2016
\> people still using RSA
\> RSA for encryption (as opposed to handshake)
\> not using stream ciphers (or block ciphers in CTR mode)
wtf<|eor|><|sor|>You're basically summarizing all the points the post made.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | sarciszewski | dbq2zyw | <|sols|><|sot|>Everything You Know About Public-Key Encryption in PHP is Wrong<|eot|><|sol|>https://paragonie.com/blog/2016/12/everything-you-know-about-public-key-encryption-in-php-is-wrong<|eol|><|sor|>The title of this post and the article are both a bit click-bait-y. The title makes it seem like PHP and its libraries are unsafe to use, when in fact the only complaint the author makes is about one PHP function with an insecure default (rightfully so, but hard to change between versions).
Crypto primitives need to be understood thoroughly to be able to use them properly - regardless of the language. If I dont know that I shouldn't use PKCS1 or ECB, well, maybe I should read a crypto book or take a course on Coursera (can recommend!). That is in no way PHP's fault though...
The summary of the article is also very strange and tbh simply wrong: "don't use RSA", really?<|eor|><|sor|>> If I dont know that I shouldn't use PKCS1 or ECB, well, maybe I should read a crypto book or take a course on Coursera (can recommend!). That is in no way PHP's fault though...
You're [blaming the user](https://cr.yp.to/talks/2015.01.07/slides-djb-20150107-a4.pdf) when we should be giving them better tools.<|eor|><|sor|>Unfortunately that's absolutely true. I am blaming the user... In crypto, for some reason, the APIs are incredibly bad and complicated and require the user to know all these primitives. Having an encrypt() and decrypt() function without any parameter bullshit would be great. Much like the password_hash() function. Until we have that, users have to know more than they should have to ....<|eor|><|sor|>> Having an encrypt() and decrypt() function without any parameter bullshit would be great.
Incidentally:
* [Halite](https://github.com/paragonie/halite)
* [defuse/php-encryption](https://github.com/defuse/php-encryption)
* [Zend\Crypt](https://github.com/zendframework/zend-crypt/blob/master/doc/book/hybrid.md) (recent versions)
This is precisely what I've been pushing for, for years.
(Sometimes my pushes to make PHP better end up here on /r/lolphp and I scratch my head in confusion.)<|eor|><|eols|><|endoftext|> | 5 |
lolphp | Danack | 3jvcxh | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|eols|><|endoftext|> | 42 |
lolphp | polish_niceguy | cusrwz8 | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>It's lolrasmus, not lolphp. This idiot generated map with all the vendor libraries like Faker, phpDocumentor, Symfony, etc.
He's just jealous that Laravel turned his retarded child into something usable.<|eor|><|eols|><|endoftext|> | 36 |
lolphp | Vakieh | cusuqal | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>Yeah!
Who needs a class hierarchy, with abstraction, and encapsulation, and actual idiomatic patterns?
Just code the entire language into a single file, you probably only need a big list of globals anyway right?
Some languages get a Guido, and some get... this moron.<|eor|><|eols|><|endoftext|> | 18 |
lolphp | greyfade | cut8oju | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>It's lolrasmus, not lolphp. This idiot generated map with all the vendor libraries like Faker, phpDocumentor, Symfony, etc.
He's just jealous that Laravel turned his retarded child into something usable.<|eor|><|sor|>Yeah, it's not as if Rasmus [knows what he's doing.](https://en.wikiquote.org/wiki/Rasmus_Lerdorf)<|eor|><|eols|><|endoftext|> | 17 |
lolphp | BilgeXA | cusmwo6 | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>>Lerdorf looking at Laravel
Uh oh... this can only spell disaster.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | myaut | cutchrz | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>It's so bad you should even be careful opening the image (as it's HUUUUUGE). It froze my PC for a good half a minute before it would close.<|eor|><|sor|>It is also a JPG which is pretty bad choice for a graph. <|eor|><|eols|><|endoftext|> | 13 |
lolphp | Brainlag | cutpozf | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>It's so bad you should even be careful opening the image (as it's HUUUUUGE). It froze my PC for a good half a minute before it would close.<|eor|><|sor|>It is also a JPG which is pretty bad choice for a graph. <|eor|><|sor|>He really tries hard to perpetuate his stereotype.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | Kerfulfel | cutr658 | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>It's lolrasmus, not lolphp. This idiot generated map with all the vendor libraries like Faker, phpDocumentor, Symfony, etc.
He's just jealous that Laravel turned his retarded child into something usable.<|eor|><|sor|>Yeah, it's not as if Rasmus [knows what he's doing.](https://en.wikiquote.org/wiki/Rasmus_Lerdorf)<|eor|><|sor|>"Back when PHP had less than 100 functions and the function hashing mechanism was strlen()" hahaha oh my<|eor|><|eols|><|endoftext|> | 10 |
lolphp | greyfade | cuttf2a | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>It's lolrasmus, not lolphp. This idiot generated map with all the vendor libraries like Faker, phpDocumentor, Symfony, etc.
He's just jealous that Laravel turned his retarded child into something usable.<|eor|><|sor|>Yeah, it's not as if Rasmus [knows what he's doing.](https://en.wikiquote.org/wiki/Rasmus_Lerdorf)<|eor|><|sor|>"Back when PHP had less than 100 functions and the function hashing mechanism was strlen()" hahaha oh my<|eor|><|sor|>... Which is why it has such an inconsistent naming scheme for the core functions.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | beerdude26 | cutdv0s | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>It's lolrasmus, not lolphp. This idiot generated map with all the vendor libraries like Faker, phpDocumentor, Symfony, etc.
He's just jealous that Laravel turned his retarded child into something usable.<|eor|><|sor|>Yeah, it's not as if Rasmus [knows what he's doing.](https://en.wikiquote.org/wiki/Rasmus_Lerdorf)<|eor|><|sor|>Oh god this is horrible<|eor|><|eols|><|endoftext|> | 8 |
lolphp | Sheepshow | cux4kv5 | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>It's so bad you should even be careful opening the image (as it's HUUUUUGE). It froze my PC for a good half a minute before it would close.<|eor|><|sor|>It is also a JPG which is pretty bad choice for a graph. <|eor|><|sor|>He really tries hard to perpetuate his stereotype.<|eor|><|sor|>The sidebar of his own twitter says "Breaking the web." I've lost all doubt that he is, in fact, the greatest internet troll, nay, meta-troll, who has ever lived.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | gearvOsh | cusqze8 | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>IMO, this would prove a better point if dev dependencies weren't included. Those seem to make up the majority.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | TweetPoster | cuskogd | <|sols|><|sot|>A partial map of Laravel's class hierarchy<|eot|><|sol|>https://twitter.com/rasmus/status/618301957095055360/photo/1<|eol|><|sor|>[**@rasmus**](https://twitter.com/rasmus):
>[2015-07-07 06:14:08 UTC](https://twitter.com/rasmus/status/618301957095055360)
>I was getting lost in Laravel's class hierarchy so I had phan spit out a \*partial\* map of it! [*lerdorf.com*](http://lerdorf.com/laravel.jpg) [*pic.twitter.com*](http://pbs.twimg.com/media/CJSmWlPUcAA4iRo.jpg) [^[Imgur]](http://i.imgur.com/WJNzxiP.jpg)
----
[^[Mistake?]](/compose/?to=TweetPoster&subject=Error%20Report&message=/3jvcxh%0A%0APlease leave above link unaltered.)
[^[Suggestion]](/message/compose/?to=TweetPoster&subject=Suggestion)
[^[FAQ]](/r/TweetPoster/comments/13relk/)
[^[Code]](https://github.com/buttscicles/TweetPoster)
[^[Issues]](https://github.com/buttscicles/TweetPoster/issues)
<|eor|><|eols|><|endoftext|> | 5 |
lolphp | callcifer | 2qyuhc | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|eoss|><|endoftext|> | 46 |
lolphp | allthediamonds | cnb41qs | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>Wait, what? So they're going to accept type hinting, but do type juggling with the values passed automatically to make them conform? Jesus.
I thought they had learned from their mistakes and were keeping type juggling alive only for retrocompatibility reasons, but no, here they're actually encouraging it.
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.
That's the biggest load of bullshit I've ever read.
EDIT: Wait, wait, it gets worse! Turns out that the casting rules for this are not the same as the casting rules for the rest of PHP. For example, in PHP, arrays can be casted as strings (they turn into the string "Array") but here it will be a fatal error.
So this is essentially a different type juggling implementation. Great.<|eor|><|eoss|><|endoftext|> | 30 |
lolphp | expugnator3000 | cnat4dh | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>> not forcing users to worry about type conversions
That's exactly what this does, yet they claim the opposite. PHP seems to be designed around this idea.
Statically typed languages tell me at compile time that something is wrong, dynamically typed languages at least do this at runtime. PHP almost always does the wrong thing by rarely telling you at all.<|eor|><|eoss|><|endoftext|> | 26 |
lolphp | BufferUnderpants | cnb5g08 | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>> not forcing users to worry about type conversions
That's exactly what this does, yet they claim the opposite. PHP seems to be designed around this idea.
Statically typed languages tell me at compile time that something is wrong, dynamically typed languages at least do this at runtime. PHP almost always does the wrong thing by rarely telling you at all.<|eor|><|sor|>Implicit casting is often confusing, but I can see why *some* parts of the language would have it. I maintain the type coercion system for Active Record in Ruby on Rails. While I do my best to make sure everything is explicit, and just fail in cases that were likely due to programmer error. However, in a web language, input is going to come in the form of a string. Parsed request body? String. Database query result? String.
In cases where input is almost certainly from one of those two sources (such as an ORM), coercion does remove a lot of headaches from the user.
But yeah, PHP's semantics for it are fucking ridiculous.<|eor|><|sor|>> Database query result? String.
Your database would be enforcing types. Unless you store everything as varchar.<|eor|><|sor|>> Unless you store everything as varchar.
Remember where you are.<|eor|><|eoss|><|endoftext|> | 20 |
lolphp | urquan | cnb3gwd | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>I see that in pure PHP tradition they're defining several ways to say the same thing by defining both `int` and `integer` as well as `bool` and `boolean`. That way you can stay fresh and avoid writing the same code twice. Catering to all skill as well as sanity levels.<|eor|><|eoss|><|endoftext|> | 19 |
lolphp | quickjoe_smith | cnatmom | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>> not forcing users to worry about type conversions
That's exactly what this does, yet they claim the opposite. PHP seems to be designed around this idea.
Statically typed languages tell me at compile time that something is wrong, dynamically typed languages at least do this at runtime. PHP almost always does the wrong thing by rarely telling you at all.<|eor|><|sor|>I always thought Perl had the right idea in terms of balancing convenience and avoiding surprises, in that the comparison operators drove the type coercion (`eq`, `lt`, `gt`, `le`, `ge` for string comparisons, `==`, `<`, `>`, `<=`, `>=` for numeric).
As the programmer, you're always in control of the comparison without hacks or having to remember a lot of complex/inconsistent/undocumented implicit conversion rules of the language.<|eor|><|eoss|><|endoftext|> | 13 |
lolphp | duskwuff | cnavjpe | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>Question...
PHP....7?
Is PHP operating on an "odd number only" release cycle now?<|eor|><|sor|>PHP 6 was supposed to be the all-singing, all-dancing, all-Unicode release, and was supposed to succeed PHP 5.2. It died a nasty death, and 5.3 came out instead; some of the features it was supposed to include trickled in with later versions.
Since the "real" PHP 6 was announced, but is never going to be released in that form, the development team decided to skip that version number and jump straight to 7.<|eor|><|eoss|><|endoftext|> | 13 |
lolphp | rabidferret | cnavr9k | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>Question...
PHP....7?
Is PHP operating on an "odd number only" release cycle now?<|eor|><|sor|>PHP 6 was designed only to work with ECMAScript 4.<|eor|><|eoss|><|endoftext|> | 12 |
lolphp | n1c0_ds | cnb96ih | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>Question...
PHP....7?
Is PHP operating on an "odd number only" release cycle now?<|eor|><|sor|>They figured giving the released PHP a different number than the failed PHP 6, it would make Googling issues easier. It's actually sensible for once.<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | InconsiderateBastard | cnavmct | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>Question...
PHP....7?
Is PHP operating on an "odd number only" release cycle now?<|eor|><|sor|>They tried to make PHP6 but they failed.
They're trying again as PHP7. If that fails too, I assume they'lll try PHP8 after that.<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | Rhomboid | cnaxren | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>Question...
PHP....7?
Is PHP operating on an "odd number only" release cycle now?<|eor|><|sor|>Some simpletons thought that other simpletons of the world would be confused by a few books written 6+ years ago that mentioned PHP 6 in their titles, when that PHP 6 was what eventually became PHP 5.3 and this upcoming PHP 6 would be an actual 2015-era new release.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | expugnator3000 | cnbo49h | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>Question...
PHP....7?
Is PHP operating on an "odd number only" release cycle now?<|eor|><|sor|>They tried to make PHP6 but they failed.
They're trying again as PHP7. If that fails too, I assume they'lll try PHP8 after that.<|eor|><|sor|>Perhaps they will switch to Roman numbering, calling it IIX
Or NT<|eor|><|sor|>PHP XP: *The Experience.*<|eor|><|sor|>**P**retty **H**orrifying **P**rogramming E**xp**erience<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | vytah | cnbdj7w | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>Question...
PHP....7?
Is PHP operating on an "odd number only" release cycle now?<|eor|><|sor|>PHP 6 was a project aiming to redesign several important parts of the language, mostly Unicode support. It failed (what a surprise...), but it didn't stop some cash-grabbers from releasing [multiple PHP 6 books](https://www.google.com/search?hl=en&q=php%206%20book&gbv=2&gws_rd=ssl&tbm=isch).
When PHP devs decided to attempt creating a new major version again (this time tackling the issue from another angle), they decided that calling it "PHP 6" would be confusing people would buy outdated books, the cash-grabbers would succeed, and so on.
It's nothing unusual: Winamp skipped version 4, MS Office skipped (internal) version 13, Slackware skipped versions 5 and 6, Windows skipped (customer-facing) version 9.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | rabidferret | cnavs80 | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>> not forcing users to worry about type conversions
That's exactly what this does, yet they claim the opposite. PHP seems to be designed around this idea.
Statically typed languages tell me at compile time that something is wrong, dynamically typed languages at least do this at runtime. PHP almost always does the wrong thing by rarely telling you at all.<|eor|><|sor|>Implicit casting is often confusing, but I can see why *some* parts of the language would have it. I maintain the type coercion system for Active Record in Ruby on Rails. While I do my best to make sure everything is explicit, and just fail in cases that were likely due to programmer error. However, in a web language, input is going to come in the form of a string. Parsed request body? String. Database query result? String.
In cases where input is almost certainly from one of those two sources (such as an ORM), coercion does remove a lot of headaches from the user.
But yeah, PHP's semantics for it are fucking ridiculous.<|eor|><|sor|>Oh also we have a schema, so you at least know the expected type coming out.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | OneWingedShark | cnetrj6 | <|soss|><|sot|>New RFC for scalar types in PHP 7!<|eot|><|sost|>As expected, [the new RFC](https://wiki.php.net/rfc/scalar_type_hints) is full of perfectly sensible, well designed, no-surprises behavior:
function foo(int $bar)
{
return $bar + 2;
}
foo("7PHP"); // returns 9
How about booleans?
function foo(bool $bar)
{
return $bar === true;
}
foo(new stdClass()); // returns true
Of course even *that* is not always true:
foo(new SimpleXMLElement('<b></b>')); // returns false
So yeah, these scalar "types" will actually accept *[almost anything](https://wiki.php.net/rfc/scalar_type_hints#example)* (it can't be *everything* because then it would be consistent, the horror!) and then use PHP's mind-numbingly broken casting semantics to coerce them to the desired type. Why bother introducing this "feature" if you aren't going to *actually enforce* the types?
Fear not! They do have an answer for that:
> By allowing conversion instead of requiring strict type matches, this RFC is in keeping with PHP being a loosely-typed language. Finally, by not forcing users to worry about type conversions, it keeps the language accessible to beginners, keeping PHP a language catering to all skill-levels.<|eost|><|sor|>> not forcing users to worry about type conversions
That's exactly what this does, yet they claim the opposite. PHP seems to be designed around this idea.
Statically typed languages tell me at compile time that something is wrong, dynamically typed languages at least do this at runtime. PHP almost always does the wrong thing by rarely telling you at all.<|eor|><|sor|>Implicit casting is often confusing, but I can see why *some* parts of the language would have it. I maintain the type coercion system for Active Record in Ruby on Rails. While I do my best to make sure everything is explicit, and just fail in cases that were likely due to programmer error. However, in a web language, input is going to come in the form of a string. Parsed request body? String. Database query result? String.
In cases where input is almost certainly from one of those two sources (such as an ORM), coercion does remove a lot of headaches from the user.
But yeah, PHP's semantics for it are fucking ridiculous.<|eor|><|sor|>> Database query result? String.
Your database would be enforcing types. Unless you store everything as varchar.<|eor|><|sor|>When working inside of the database, yes it enforces types. However the APIs to interface with it from other languages returns a string (and potentially a type code). The semantics vary a bit by vendor and can get a bit complicated but in general you can assume you'll get back a string from the database library even if the column is an int.<|eor|><|sor|>> When working inside of the database, yes it enforces types. However the APIs to interface with it from other languages returns a string (and potentially a type code).
What a waste.<|eor|><|sor|>Not really. Other than integer types, there is no way to represent the value in a way that can cross language barriers.<|eor|><|sor|>> Not really. Other than integer types, there is no way to represent the value in a way that can cross language barriers.
0. We don't *always* need to cross language barriers. (Ada and SQL implementations have the ability to share a common intermediate form describing types ([DIANA](http://en.wikipedia.org/wiki/DIANA_%28intermediate_language%29)), IIRC: oracle and PL/SQL, both.)
0. Secondly, there's [ASN.1](http://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One) which *CAN* transmit values across languages, and architectures/platforms.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | denilsonsa | 2ad68f | <|sols|><|sot|>bindParam('foo', $value, PDO::PARAM_INT) will change $value to string.<|eot|><|sol|>http://php.net/manual/en/pdostatement.bindparam.php#94711<|eol|><|eols|><|endoftext|> | 42 |
lolphp | Myto | ciu5sq9 | <|sols|><|sot|>bindParam('foo', $value, PDO::PARAM_INT) will change $value to string.<|eot|><|sol|>http://php.net/manual/en/pdostatement.bindparam.php#94711<|eol|><|sor|>["Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called."](http://php.net/manual/en/pdostatement.bindparam.php)
So what does one expect when they pass something by reference? Nobody said you would get back what you put in, and it makes perfect sense you would get a string back in this case.
"Lol, php does exactly what the manual says it is supposed to do."<|eor|><|sor|>Uh... no. The observed behavior makes no sense and the part of the manual you quoted does not in any way describe it.<|eor|><|sor|>We are talking about the Steve M post, right?
So, uh... yes. The observed behavior makes perfect sense.
$active = 1;
var_dump($active);
result int
$ps->bindParam(":active", $active, PDO::PARAM_INT);
var_dump($active);
Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called."
result int
$ps->execute();
var_dump($active);
result string "1"
How is that in any way NOT the observed behavior EXACTLY described by what I quoted from the website? You bindParam, nothing happens. You execute the PDO statement, PDO does WHATEVER IT WANTS WITH YOUR VAR THAT WAS PASSED **BY REFERENCE** (and in this case turns it into a string because that's what it decided was best), and so you get back a string. Just because you tell PDO that it's a PARAM_INT doesn't mean that you will GET BACK an int after it does whatever it needs to do with the value.
Explain to me how it isn't precisely correct behavior?<|eor|><|sor|>> PDO does WHATEVER IT WANTS WITH YOUR VAR THAT WAS PASSED BY REFERENCE
That's the bit that's neither sane nor documented (as far as I can see, anyway). Something being passed by reference does not imply that the value getting changed arbitrarily is somehow correct.
I guess this is a bug somehow related to handling of output parameters. In case of an actual output parameter (PDO::PARAM_INPUT_OUTPUT) it might make sense.
<|eor|><|eols|><|endoftext|> | 18 |
lolphp | kasnalin | ciu5yto | <|sols|><|sot|>bindParam('foo', $value, PDO::PARAM_INT) will change $value to string.<|eot|><|sol|>http://php.net/manual/en/pdostatement.bindparam.php#94711<|eol|><|sor|>["Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called."](http://php.net/manual/en/pdostatement.bindparam.php)
So what does one expect when they pass something by reference? Nobody said you would get back what you put in, and it makes perfect sense you would get a string back in this case.
"Lol, php does exactly what the manual says it is supposed to do."<|eor|><|sor|>Uh... no. The observed behavior makes no sense and the part of the manual you quoted does not in any way describe it.<|eor|><|sor|>We are talking about the Steve M post, right?
So, uh... yes. The observed behavior makes perfect sense.
$active = 1;
var_dump($active);
result int
$ps->bindParam(":active", $active, PDO::PARAM_INT);
var_dump($active);
Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called."
result int
$ps->execute();
var_dump($active);
result string "1"
How is that in any way NOT the observed behavior EXACTLY described by what I quoted from the website? You bindParam, nothing happens. You execute the PDO statement, PDO does WHATEVER IT WANTS WITH YOUR VAR THAT WAS PASSED **BY REFERENCE** (and in this case turns it into a string because that's what it decided was best), and so you get back a string. Just because you tell PDO that it's a PARAM_INT doesn't mean that you will GET BACK an int after it does whatever it needs to do with the value.
Explain to me how it isn't precisely correct behavior?<|eor|><|sor|>Just because it _can_ do whatever it wants with the reference doesn't mean it _should_.<|eor|><|eols|><|endoftext|> | 16 |
lolphp | Myto | ciu4290 | <|sols|><|sot|>bindParam('foo', $value, PDO::PARAM_INT) will change $value to string.<|eot|><|sol|>http://php.net/manual/en/pdostatement.bindparam.php#94711<|eol|><|sor|>["Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called."](http://php.net/manual/en/pdostatement.bindparam.php)
So what does one expect when they pass something by reference? Nobody said you would get back what you put in, and it makes perfect sense you would get a string back in this case.
"Lol, php does exactly what the manual says it is supposed to do."<|eor|><|sor|>Uh... no. The observed behavior makes no sense and the part of the manual you quoted does not in any way describe it.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | ahruss | ciudf14 | <|sols|><|sot|>bindParam('foo', $value, PDO::PARAM_INT) will change $value to string.<|eot|><|sol|>http://php.net/manual/en/pdostatement.bindparam.php#94711<|eol|><|sor|>["Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called."](http://php.net/manual/en/pdostatement.bindparam.php)
So what does one expect when they pass something by reference? Nobody said you would get back what you put in, and it makes perfect sense you would get a string back in this case.
"Lol, php does exactly what the manual says it is supposed to do."<|eor|><|sor|>Uh... no. The observed behavior makes no sense and the part of the manual you quoted does not in any way describe it.<|eor|><|sor|>We are talking about the Steve M post, right?
So, uh... yes. The observed behavior makes perfect sense.
$active = 1;
var_dump($active);
result int
$ps->bindParam(":active", $active, PDO::PARAM_INT);
var_dump($active);
Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called."
result int
$ps->execute();
var_dump($active);
result string "1"
How is that in any way NOT the observed behavior EXACTLY described by what I quoted from the website? You bindParam, nothing happens. You execute the PDO statement, PDO does WHATEVER IT WANTS WITH YOUR VAR THAT WAS PASSED **BY REFERENCE** (and in this case turns it into a string because that's what it decided was best), and so you get back a string. Just because you tell PDO that it's a PARAM_INT doesn't mean that you will GET BACK an int after it does whatever it needs to do with the value.
Explain to me how it isn't precisely correct behavior?<|eor|><|sor|>> PDO does WHATEVER IT WANTS WITH YOUR VAR THAT WAS PASSED BY REFERENCE
That's the bit that's neither sane nor documented (as far as I can see, anyway). Something being passed by reference does not imply that the value getting changed arbitrarily is somehow correct.
I guess this is a bug somehow related to handling of output parameters. In case of an actual output parameter (PDO::PARAM_INPUT_OUTPUT) it might make sense.
<|eor|><|sor|>It doesn't make it incorrect, either. It doesn't make it ANYTHING. That's the point!
You don't hand-over your car keys to a stranger on the street with the expectation of having it returned to you in the same condition as you left it. As I said to another in this thread, you are projecting YOUR expectations into a situation where none are given or implied.
function MagicalBlackHole is defined as
function MagicalBlackHole(&$ref)
What is the expected value and / or type of $myvalue after the following code is run?
$myvalue = 5;
MagicalBlackHole($myvalue);
var_dump($myvalue);
???
You aren't told what happens with the value that is passed by reference. You aren't given any guarantees. None are even hinted at. You are simply told that you pass a value by a reference and then something happens.
This is precisely what is happening with PDO. The PDO function isn't some function designed to transform some set of values in some way and then return to you something specific. No. Not at all. The PDO function takes some values... and that's all. What it does is neither here nor there.
You were given no REASON to expect that same value back. That expectation is purely your own because... just because you want it that way, and lots of other functions happen to be that way, but not all and not this one.
If anything you SHOULD expect it to be different BECAUSE no expectations or guarantees were provided! Unless you can find some documentation showing that the value is meant to be the same after all is said and done then the expectation should be that the value is garbage (and not even necessarily anything even resembling the original value).<|eor|><|sor|>Uh
The documentation is pretty clear, here. It's taken as reference so that it can only evaluate it when you make the call. You haven't made the call yet, but it's both evaluated and made destructive modifications to your variable. This is not sensible, the documentation implies not only that it will be untouched until you run the query, but also that the variable is perfectly safe to use until you do so--that's the entire point of it being taken as a reference, as far as I can tell, so that it can be updated later.
Did you write this function, or something? <|eor|><|sor|>How do you figure that it changing from an int to a string DIRECTLY AFTER the call to the execute function is not making the call / running the query? Explain that to me, please. If the execute function isn't running the query, as you say isn't happening here, then what IS happening and what does execute do?
It's not like I quoted the docs precisely saying that the value is evaluated when you call execute... **except that this is the very first thing I posted in this thread!**
And furthermore, the "entire point of it being taken as reference" is so that you can use that variable in a loop to only update that particular value within your query and execute the query, as opposed to having to continually rebind the variable over and over with bindValue.
Again, you CAN NOT pass a variable by reference and expect to get back what you put in. There has never, ever, been any guarantees on that. It's never been implied. It has never even been hinted at. In fact, it's only smart to consider the value in your variable to now be junk. Unless it's being passed to your own function and thus know exactly what is being done, or you are using a function that has documentation explaining what happens and what effects to expect, then you have never had any reason to expect anything but junk back. Not ever. Not in ANY function in ANY language.
There are plenty of functions in languages like C that take pointers and don't cause side-effects. Sure. That's the nature of those functions. There will also be plenty of functions out there in various situations where you pass by reference and your variable gets trashed. That's the nature of passing by reference. You can't impose an expectation on getting your variable back how you gave it just because it makes you feel good to expect that. It's not realistic or sensible to expect anything, and with this PDO function you have to expect to get back something different to what you put in as has been demonstrated with this int to string example.
What would you have PDO do instead? Waste time making a copy of your variable that it then trashes as it sees fit? That's purely inefficient. If there is a need to maintain the sanctity of your variable then YOU ensure you have a copy, else PDO isn't going to waste time possibly copying some fuck-off huge string just to make lazy coders with unsolicited expectations feel any better about PDO.
No, I have no associations with PHP or PDO. Thanks for asking.
So afaic you are wrong in both points you tried to make. Explain to me how I'm wrong with what I've said, and explain to me where this ludicrous idea that you can pass by reference and get your original values back has come from? What you have said says to me you are not only wrong, but you don't even understand WHY it would be the way it is and haven't even figured that out on your own through intuition.<|eor|><|sor|>Have you ever heard of the principle of least surprise? That is why it should not change your variable. There is really no reason for it to need to do so.
The fact that it's documented doesn't make it okay.
The fact that you are passing by reference (impossible to see at the call site) doesn't make it reasonable.
This makes code harder to read and maintain, and it is ridiculous.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | phoshi | ciub3s6 | <|sols|><|sot|>bindParam('foo', $value, PDO::PARAM_INT) will change $value to string.<|eot|><|sol|>http://php.net/manual/en/pdostatement.bindparam.php#94711<|eol|><|sor|>["Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called."](http://php.net/manual/en/pdostatement.bindparam.php)
So what does one expect when they pass something by reference? Nobody said you would get back what you put in, and it makes perfect sense you would get a string back in this case.
"Lol, php does exactly what the manual says it is supposed to do."<|eor|><|sor|>Uh... no. The observed behavior makes no sense and the part of the manual you quoted does not in any way describe it.<|eor|><|sor|>We are talking about the Steve M post, right?
So, uh... yes. The observed behavior makes perfect sense.
$active = 1;
var_dump($active);
result int
$ps->bindParam(":active", $active, PDO::PARAM_INT);
var_dump($active);
Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called."
result int
$ps->execute();
var_dump($active);
result string "1"
How is that in any way NOT the observed behavior EXACTLY described by what I quoted from the website? You bindParam, nothing happens. You execute the PDO statement, PDO does WHATEVER IT WANTS WITH YOUR VAR THAT WAS PASSED **BY REFERENCE** (and in this case turns it into a string because that's what it decided was best), and so you get back a string. Just because you tell PDO that it's a PARAM_INT doesn't mean that you will GET BACK an int after it does whatever it needs to do with the value.
Explain to me how it isn't precisely correct behavior?<|eor|><|sor|>> PDO does WHATEVER IT WANTS WITH YOUR VAR THAT WAS PASSED BY REFERENCE
That's the bit that's neither sane nor documented (as far as I can see, anyway). Something being passed by reference does not imply that the value getting changed arbitrarily is somehow correct.
I guess this is a bug somehow related to handling of output parameters. In case of an actual output parameter (PDO::PARAM_INPUT_OUTPUT) it might make sense.
<|eor|><|sor|>It doesn't make it incorrect, either. It doesn't make it ANYTHING. That's the point!
You don't hand-over your car keys to a stranger on the street with the expectation of having it returned to you in the same condition as you left it. As I said to another in this thread, you are projecting YOUR expectations into a situation where none are given or implied.
function MagicalBlackHole is defined as
function MagicalBlackHole(&$ref)
What is the expected value and / or type of $myvalue after the following code is run?
$myvalue = 5;
MagicalBlackHole($myvalue);
var_dump($myvalue);
???
You aren't told what happens with the value that is passed by reference. You aren't given any guarantees. None are even hinted at. You are simply told that you pass a value by a reference and then something happens.
This is precisely what is happening with PDO. The PDO function isn't some function designed to transform some set of values in some way and then return to you something specific. No. Not at all. The PDO function takes some values... and that's all. What it does is neither here nor there.
You were given no REASON to expect that same value back. That expectation is purely your own because... just because you want it that way, and lots of other functions happen to be that way, but not all and not this one.
If anything you SHOULD expect it to be different BECAUSE no expectations or guarantees were provided! Unless you can find some documentation showing that the value is meant to be the same after all is said and done then the expectation should be that the value is garbage (and not even necessarily anything even resembling the original value).<|eor|><|sor|>Uh
The documentation is pretty clear, here. It's taken as reference so that it can only evaluate it when you make the call. You haven't made the call yet, but it's both evaluated and made destructive modifications to your variable. This is not sensible, the documentation implies not only that it will be untouched until you run the query, but also that the variable is perfectly safe to use until you do so--that's the entire point of it being taken as a reference, as far as I can tell, so that it can be updated later.
Did you write this function, or something? <|eor|><|eols|><|endoftext|> | 10 |
lolphp | ahruss | ciudful | <|sols|><|sot|>bindParam('foo', $value, PDO::PARAM_INT) will change $value to string.<|eot|><|sol|>http://php.net/manual/en/pdostatement.bindparam.php#94711<|eol|><|sor|>Also, the second parameter:
> variable
> Name of the PHP variable to bind to the SQL statement parameter.
This makes it sound like you use it like `$stmt->bindParam(":param", "variableName"),` which isn't accurate. <|eor|><|eols|><|endoftext|> | 9 |
lolphp | StephenSwat | 25eqcr | <|soss|><|sot|>Encountered this trying to strip non-numeric characters from a string...<|eot|><|sost|> preg_replace('/[^0-9]/', '', '123abc45', -1 );
Now, let's see the output of that per PHP version:
* 4.4.9: 12345
* 5.1.6: 12345
* 5.3.0: 12345
* 5.4.3: 12345
* 5.4.4: 123abc45
* 5.4.5: 12345
* 5.4.21: 12345
* 5.5.5: 12345
lolphp<|eost|><|eoss|><|endoftext|> | 46 |
lolphp | deadstone | chgq5v4 | <|soss|><|sot|>Encountered this trying to strip non-numeric characters from a string...<|eot|><|sost|> preg_replace('/[^0-9]/', '', '123abc45', -1 );
Now, let's see the output of that per PHP version:
* 4.4.9: 12345
* 5.1.6: 12345
* 5.3.0: 12345
* 5.4.3: 12345
* 5.4.4: 123abc45
* 5.4.5: 12345
* 5.4.21: 12345
* 5.5.5: 12345
lolphp<|eost|><|sor|>It's a feature. How else are you supposed to tell if you're running 5.4.4?<|eor|><|eoss|><|endoftext|> | 33 |
lolphp | andsens | chh83k5 | <|soss|><|sot|>Encountered this trying to strip non-numeric characters from a string...<|eot|><|sost|> preg_replace('/[^0-9]/', '', '123abc45', -1 );
Now, let's see the output of that per PHP version:
* 4.4.9: 12345
* 5.1.6: 12345
* 5.3.0: 12345
* 5.4.3: 12345
* 5.4.4: 123abc45
* 5.4.5: 12345
* 5.4.21: 12345
* 5.5.5: 12345
lolphp<|eost|><|sor|>Can't reproduce : http://3v4l.org/bZeBl
(Also, the limit parameter is optional.)<|eor|><|sor|>On wheezy; can't reproduce either.
PHP Version 5.4.4-14+deb7u9<|eor|><|sor|>> -14+deb7u9
There's your *problem*, Debian maintainers fixed it for you :-)<|eor|><|eoss|><|endoftext|> | 13 |
lolphp | Krenair | chhbhuy | <|soss|><|sot|>Encountered this trying to strip non-numeric characters from a string...<|eot|><|sost|> preg_replace('/[^0-9]/', '', '123abc45', -1 );
Now, let's see the output of that per PHP version:
* 4.4.9: 12345
* 5.1.6: 12345
* 5.3.0: 12345
* 5.4.3: 12345
* 5.4.4: 123abc45
* 5.4.5: 12345
* 5.4.21: 12345
* 5.5.5: 12345
lolphp<|eost|><|sor|>That's unsettling.<|eor|><|soopr|>What's even worse is that Debian Wheezy comes with PHP 5.4.4, so I should think this affects quite a lot of people.<|eoopr|><|sor|>Don't worry. The Debian maintainers got your back and fixed it downstream. [Here's the entire changelog](http://metadata.ftp-master.debian.org/changelogs//main/p/php5/php5_5.4.4-14+deb7u9_changelog).
Didn't Ubuntu Server ship with 5.4.0 at some point? It's just one of those things that have convinced me that choosing Debian as a server distro is definitely the right choice.<|eor|><|sor|>> * upstream fix: Segfault calling bind_param() on mysqli
> * upstream fix: the socket_connect() won't work with IPv6 address
I stopped reading after these first two lines. WTF, PHP?<|eor|><|eoss|><|endoftext|> | 11 |
lolphp | chazzeromus | chgq7hg | <|soss|><|sot|>Encountered this trying to strip non-numeric characters from a string...<|eot|><|sost|> preg_replace('/[^0-9]/', '', '123abc45', -1 );
Now, let's see the output of that per PHP version:
* 4.4.9: 12345
* 5.1.6: 12345
* 5.3.0: 12345
* 5.4.3: 12345
* 5.4.4: 123abc45
* 5.4.5: 12345
* 5.4.21: 12345
* 5.5.5: 12345
lolphp<|eost|><|sor|>That's unsettling.<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | andsens | chh82ah | <|soss|><|sot|>Encountered this trying to strip non-numeric characters from a string...<|eot|><|sost|> preg_replace('/[^0-9]/', '', '123abc45', -1 );
Now, let's see the output of that per PHP version:
* 4.4.9: 12345
* 5.1.6: 12345
* 5.3.0: 12345
* 5.4.3: 12345
* 5.4.4: 123abc45
* 5.4.5: 12345
* 5.4.21: 12345
* 5.5.5: 12345
lolphp<|eost|><|sor|>That's unsettling.<|eor|><|soopr|>What's even worse is that Debian Wheezy comes with PHP 5.4.4, so I should think this affects quite a lot of people.<|eoopr|><|sor|>Don't worry. The Debian maintainers got your back and fixed it downstream. [Here's the entire changelog](http://metadata.ftp-master.debian.org/changelogs//main/p/php5/php5_5.4.4-14+deb7u9_changelog).
Didn't Ubuntu Server ship with 5.4.0 at some point? It's just one of those things that have convinced me that choosing Debian as a server distro is definitely the right choice.<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | StephenSwat | chgqrwp | <|soss|><|sot|>Encountered this trying to strip non-numeric characters from a string...<|eot|><|sost|> preg_replace('/[^0-9]/', '', '123abc45', -1 );
Now, let's see the output of that per PHP version:
* 4.4.9: 12345
* 5.1.6: 12345
* 5.3.0: 12345
* 5.4.3: 12345
* 5.4.4: 123abc45
* 5.4.5: 12345
* 5.4.21: 12345
* 5.5.5: 12345
lolphp<|eost|><|sor|>That's unsettling.<|eor|><|soopr|>What's even worse is that Debian Wheezy comes with PHP 5.4.4, so I should think this affects quite a lot of people.<|eoopr|><|eoss|><|endoftext|> | 6 |
lolphp | more_exercise | 14o9ax | <|sols|><|sot|>You can goto the try{} block from the catch block. Yes. That sounds like a good idea, let's do that.<|eot|><|sol|>http://phpmanualmasterpieces.tumblr.com/post/33091353115/the-documentation-clearly-says-raptors<|eol|><|eols|><|endoftext|> | 38 |
lolphp | catcradle5 | c7gem9s | <|sols|><|sot|>You can goto the try{} block from the catch block. Yes. That sounds like a good idea, let's do that.<|eot|><|sol|>http://phpmanualmasterpieces.tumblr.com/post/33091353115/the-documentation-clearly-says-raptors<|eol|><|sor|>To be fair, if you're using goto's you've officially forfeited the right to have managable and sensible code.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | gecko | c7j1sz0 | <|sols|><|sot|>You can goto the try{} block from the catch block. Yes. That sounds like a good idea, let's do that.<|eot|><|sol|>http://phpmanualmasterpieces.tumblr.com/post/33091353115/the-documentation-clearly-says-raptors<|eol|><|sor|>You know, I hate a lot of PHP features, but I do legitimately get this one.
Quite a few older languages (e.g., Smalltalk, Common Lisp, most implementations of Scheme exceptions, Dylan, and probably others) allow you to *resume the exception*. What this means is that, in addition to simply exiting the equivalent of the `catch` block, you can also return to the expression that threw the exception, either re-executing it, or returning from it with a custom value.
Why would you want to do this, you ask? Well, for one example, it turns out it can actually be a really clean way to represent reading files that are generally structured, but occasionally have bad data, e.g. from an earlier, buggy version of the program. In this case, the main reading code is very clean, only expecting the perfect data format. The `catch` block, invoked on a bad data read, inspects the data stream, figures out the nature of the corruption, cleans it up according to a collection of rules ("in this version of the program, the size field was occasionally an extra byte long and little-endian, so a size of zero means read one more byte and return that instead"), and returns the cleaned-up data.
As other examples, I've seen this used in network code to reconnect to the server and resume processing; in XML parsing code to handle bad markup with complicated heuristics, while keeping the main parser clean; in code that could be interrupted so that the interrupt could be cleanly handled and then action returned to the main body, if appropriate; and more.
Should you make a habit of using `goto` in `try`/`catch` blocks? Hells no. Is there a sane reason to want to do it *sometimes*? In my opinion, yes.<|eor|><|eols|><|endoftext|> | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.