subreddit stringclasses 7
values | author stringlengths 3 20 | id stringlengths 5 7 | content stringlengths 67 30.4k | score int64 0 140k |
|---|---|---|---|---|
lolphp | SirClueless | cexgxwd | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Reminds me of a similar puzzle! This was originally for JavaScript, which is almost as sad a language as PHP.
var x = ????;
var y = ????;
x === y; // true
1/x === 1/y; // false
Edit:
isNaN(x) === false;
isNaN(y) === false;
Still yields a solution!<|eor|><|sor|>Some JS fun:
[] + []; // empty string
[] + {}; // an empty object
{} + []; // 0
{} + {}; // NaN (technically true, because object plus object *is* not a number<|eor|><|sor|>Oh man, this is from https://www.destroyallsoftware.com/talks/wat which is very much in the spirit of this subreddit even though it is all about ruby and JS.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | _vec_ | cexiscu | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Reminds me of a similar puzzle! This was originally for JavaScript, which is almost as sad a language as PHP.
var x = ????;
var y = ????;
x === y; // true
1/x === 1/y; // false
Edit:
isNaN(x) === false;
isNaN(y) === false;
Still yields a solution!<|eor|><|sor|>Set `x` and `y` to a string without a numeric value. Then `1/x` and `1/y` will be `NaN`, which never compares equal to anything, even itself.<|eor|><|sor|>Ah, the old NaN solution, works every time. Though there are numbers specific to javascript where
isNaN(x) === false;
isNaN(y) === false;
Don't be distracted by the word "number" up there, even though
typeof NaN; // Number
in javascript. For some reason. It's almost as silly as PHP sometimes!<|eor|><|sor|>Of course `NaN` is a number, what else would it be? It's a representation of the mathematical value "undefined", and in JS all mathematical values are subclasses of `Number`.
If `NaN` wasn't also a type of number then it would be a nightmare to use it as input to the mathematical operators and functions, and since it can be produced as an intermediate value in a larger equation you have to be able to use it as input to the next step.
I'd much rather have the unintuitive `typeof` response than to worry that `Math.sqrt(1/x)`, instead of returning `NaN` when `x = 0` might do something unpredictable because it has to implicitly coerce the intermediate `NaN` back into a number to operate further on it.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | phoshi | cexlcpu | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Reminds me of a similar puzzle! This was originally for JavaScript, which is almost as sad a language as PHP.
var x = ????;
var y = ????;
x === y; // true
1/x === 1/y; // false
Edit:
isNaN(x) === false;
isNaN(y) === false;
Still yields a solution!<|eor|><|sor|>Set `x` and `y` to a string without a numeric value. Then `1/x` and `1/y` will be `NaN`, which never compares equal to anything, even itself.<|eor|><|sor|>Ah, the old NaN solution, works every time. Though there are numbers specific to javascript where
isNaN(x) === false;
isNaN(y) === false;
Don't be distracted by the word "number" up there, even though
typeof NaN; // Number
in javascript. For some reason. It's almost as silly as PHP sometimes!<|eor|><|sor|>Of course `NaN` is a number, what else would it be? It's a representation of the mathematical value "undefined", and in JS all mathematical values are subclasses of `Number`.
If `NaN` wasn't also a type of number then it would be a nightmare to use it as input to the mathematical operators and functions, and since it can be produced as an intermediate value in a larger equation you have to be able to use it as input to the next step.
I'd much rather have the unintuitive `typeof` response than to worry that `Math.sqrt(1/x)`, instead of returning `NaN` when `x = 0` might do something unpredictable because it has to implicitly coerce the intermediate `NaN` back into a number to operate further on it.<|eor|><|sor|>In an exceedingly dynamic language you don't need all your return values to be subtypes of some common supertype, though given that many languages do there's a good reason why NaN has well defined and standardised semantics! I'm not sure if these specify a typing relationship, but regardless, it wouldn't be allowed to change the meaning of it so it doesn't really make a difference.
NaN is weird in all languages. It's a well defined, standardised weird. <|eor|><|eols|><|endoftext|> | 9 |
lolphp | imperfect_stars | cexb59f | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Reminds me of a similar puzzle! This was originally for JavaScript, which is almost as sad a language as PHP.
var x = ????;
var y = ????;
x === y; // true
1/x === 1/y; // false
Edit:
isNaN(x) === false;
isNaN(y) === false;
Still yields a solution!<|eor|><|eols|><|endoftext|> | 8 |
lolphp | kasnalin | cexd5rc | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Reminds me of a similar puzzle! This was originally for JavaScript, which is almost as sad a language as PHP.
var x = ????;
var y = ????;
x === y; // true
1/x === 1/y; // false
Edit:
isNaN(x) === false;
isNaN(y) === false;
Still yields a solution!<|eor|><|sor|>Set `x` and `y` to a string without a numeric value. Then `1/x` and `1/y` will be `NaN`, which never compares equal to anything, even itself.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | HelloAnnyong | cf038pj | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|> $x = 1;
$y = 1.1;
or some combination like that, because [float keys are converted to ints](http://us1.php.net/manual/en/language.types.array.php). Whee, php<|eor|><|sor|>Floats being converted to integers does actually make some kind of sense here. Saves you flooring it first.<|eor|><|sor|>But does it make more sense than allowing float keys, or converting the key to a string instead of an int?<|eor|><|sor|>Well, PHP arrays are supposed to be only int or string indexed. It'd be unusual to want to index by floats here, and the usual reason you'd end up with a float value being used as an index is because of trying to compute an integer index.<|eor|><|sor|>Is this another case of "it's intended, therefore it's coherent"? Do PHP "arrays" have an analog in literally any other programming language then? Because they're not arrays, and they're not hash tables. And like most things in PHP, they fail silently. Yay!<|eor|><|sor|>Lua tables are similar.<|eor|><|sor|>No, Lua allows non-integer, non-string keys.
http://i.imgur.com/XRkE21L.png<|eor|><|eols|><|endoftext|> | 8 |
lolphp | poizan42 | cf0bwfl | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|> $x = 1;
$y = 1.1;
or some combination like that, because [float keys are converted to ints](http://us1.php.net/manual/en/language.types.array.php). Whee, php<|eor|><|sor|>Floats being converted to integers does actually make some kind of sense here. Saves you flooring it first.<|eor|><|sor|>But does it make more sense than allowing float keys, or converting the key to a string instead of an int?<|eor|><|sor|>Well, PHP arrays are supposed to be only int or string indexed. It'd be unusual to want to index by floats here, and the usual reason you'd end up with a float value being used as an index is because of trying to compute an integer index.<|eor|><|sor|>Is this another case of "it's intended, therefore it's coherent"? Do PHP "arrays" have an analog in literally any other programming language then? Because they're not arrays, and they're not hash tables. And like most things in PHP, they fail silently. Yay!<|eor|><|sor|>Lua tables are similar.<|eor|><|sor|>I don't know whtat Lua does, but silently throwing information away without explicitly requested is generally bad design. Fine that you don't want me to use float keys, but then I should be forced to write an explicit cast to int or get an error otherwise.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | ahruss | cexg40r | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Reminds me of a similar puzzle! This was originally for JavaScript, which is almost as sad a language as PHP.
var x = ????;
var y = ????;
x === y; // true
1/x === 1/y; // false
Edit:
isNaN(x) === false;
isNaN(y) === false;
Still yields a solution!<|eor|><|sor|>Some JS fun:
[] + []; // empty string
[] + {}; // an empty object
{} + []; // 0
{} + {}; // NaN (technically true, because object plus object *is* not a number<|eor|><|eols|><|endoftext|> | 7 |
lolphp | FireyFly | cexww85 | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Reminds me of a similar puzzle! This was originally for JavaScript, which is almost as sad a language as PHP.
var x = ????;
var y = ????;
x === y; // true
1/x === 1/y; // false
Edit:
isNaN(x) === false;
isNaN(y) === false;
Still yields a solution!<|eor|><|sor|>Some JS fun:
[] + []; // empty string
[] + {}; // an empty object
{} + []; // 0
{} + {}; // NaN (technically true, because object plus object *is* not a number<|eor|><|sor|>Some more fun: Try typing these statements into `jsc`, the Firefox developer tools, or the Opera/Chrome developer tools (basically, everything I've tried so far except the Node.js REPL):
{} + [];
var a = {} + []; a;
{} + {};
var a = {} + {}; a;<|eor|><|sor|>This is because the REPLs try to parse what is input as a statement, and `{} + [];` is parsed as an empty block followed by the expression `+[]` and `{} + {};` as an empty block followed by the expression `+{}`. When you assign it to a value, it's parsed as an expression instead (due to the language's grammar).<|eor|><|eols|><|endoftext|> | 7 |
lolphp | poizan42 | cf0fnaq | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Floats being converted to integers does actually make some kind of sense here. Saves you flooring it first.<|eor|><|sor|>But does it make more sense than allowing float keys, or converting the key to a string instead of an int?<|eor|><|sor|>Well, PHP arrays are supposed to be only int or string indexed. It'd be unusual to want to index by floats here, and the usual reason you'd end up with a float value being used as an index is because of trying to compute an integer index.<|eor|><|sor|>Is this another case of "it's intended, therefore it's coherent"? Do PHP "arrays" have an analog in literally any other programming language then? Because they're not arrays, and they're not hash tables. And like most things in PHP, they fail silently. Yay!<|eor|><|sor|>Lua tables are similar.<|eor|><|sor|>I don't know whtat Lua does, but silently throwing information away without explicitly requested is generally bad design. Fine that you don't want me to use float keys, but then I should be forced to write an explicit cast to int or get an error otherwise.<|eor|><|sor|>> but silently throwing information away without explicitly requested is generally bad design
As I mentioned elsewhere, this may be a very useful feature for some applications. But it's not for everyone, I suppose.<|eor|><|sor|>You could also just force people to write (int)(some expression) instead as I suggested and no functionality would be lost, and the intent would be clear from the code.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | poizan42 | cf0bz0f | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Reminds me of a similar puzzle! This was originally for JavaScript, which is almost as sad a language as PHP.
var x = ????;
var y = ????;
x === y; // true
1/x === 1/y; // false
Edit:
isNaN(x) === false;
isNaN(y) === false;
Still yields a solution!<|eor|><|sor|>Some JS fun:
[] + []; // empty string
[] + {}; // an empty object
{} + []; // 0
{} + {}; // NaN (technically true, because object plus object *is* not a number<|eor|><|sor|>Oh man, this is from https://www.destroyallsoftware.com/talks/wat which is very much in the spirit of this subreddit even though it is all about ruby and JS.<|eor|><|sor|>Heh, the idea of weak typing usually breaks down with some serious crazyness if taken too far. In some regards is javascript worse than php in that it doesn't have a dedicated string concatenation operator.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | HelloAnnyong | cf02f38 | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|> $x = 1;
$y = 1.1;
or some combination like that, because [float keys are converted to ints](http://us1.php.net/manual/en/language.types.array.php). Whee, php<|eor|><|sor|>Floats being converted to integers does actually make some kind of sense here. Saves you flooring it first.<|eor|><|sor|>But does it make more sense than allowing float keys, or converting the key to a string instead of an int?<|eor|><|sor|>Well, PHP arrays are supposed to be only int or string indexed. It'd be unusual to want to index by floats here, and the usual reason you'd end up with a float value being used as an index is because of trying to compute an integer index.<|eor|><|sor|>Is this another case of "it's intended, therefore it's coherent"? Do PHP "arrays" have an analog in literally any other programming language then? Because they're not arrays, and they're not hash tables. And like most things in PHP, they fail silently. Yay!<|eor|><|eols|><|endoftext|> | 6 |
lolphp | adambrenecki | cexh85g | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Reminds me of a similar puzzle! This was originally for JavaScript, which is almost as sad a language as PHP.
var x = ????;
var y = ????;
x === y; // true
1/x === 1/y; // false
Edit:
isNaN(x) === false;
isNaN(y) === false;
Still yields a solution!<|eor|><|sor|>Some JS fun:
[] + []; // empty string
[] + {}; // an empty object
{} + []; // 0
{} + {}; // NaN (technically true, because object plus object *is* not a number<|eor|><|sor|>Some more fun: Try typing these statements into `jsc`, the Firefox developer tools, or the Opera/Chrome developer tools (basically, everything I've tried so far except the Node.js REPL):
{} + [];
var a = {} + []; a;
{} + {};
var a = {} + {}; a;<|eor|><|eols|><|endoftext|> | 5 |
lolphp | FireyFly | cexwt5e | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Reminds me of a similar puzzle! This was originally for JavaScript, which is almost as sad a language as PHP.
var x = ????;
var y = ????;
x === y; // true
1/x === 1/y; // false
Edit:
isNaN(x) === false;
isNaN(y) === false;
Still yields a solution!<|eor|><|sor|>Some JS fun:
[] + []; // empty string
[] + {}; // an empty object
{} + []; // 0
{} + {}; // NaN (technically true, because object plus object *is* not a number<|eor|><|sor|>Gah, I hate it when people bring these up. They point out an issue with JS, but not the issue people assume it does. These aren't all expressions; the first two are whereas the latter two are parsed as a block followed by a unary-`+` expression:
// equivalent to the latter two examples above.
{}; +[];
{}; +{};
Oh, and #2 is actually the string "[object Object]" (because `+` on two objects coerce both to string by calling their `toString` methods, which for `{}` produces "[object Object]", and for arrays join them together with `,` as a separator, which results in the empty string for the empty array).<|eor|><|eols|><|endoftext|> | 5 |
lolphp | Frimsah | cf93uij | <|sols|><|sot|>Fill in the blanks!<|eot|><|sol|>http://i.imgur.com/Wtg4OQZ.png<|eol|><|sor|>Floats being converted to integers does actually make some kind of sense here. Saves you flooring it first.<|eor|><|sor|>But does it make more sense than allowing float keys, or converting the key to a string instead of an int?<|eor|><|sor|>Well, PHP arrays are supposed to be only int or string indexed. It'd be unusual to want to index by floats here, and the usual reason you'd end up with a float value being used as an index is because of trying to compute an integer index.<|eor|><|sor|>Is this another case of "it's intended, therefore it's coherent"? Do PHP "arrays" have an analog in literally any other programming language then? Because they're not arrays, and they're not hash tables. And like most things in PHP, they fail silently. Yay!<|eor|><|sor|>Lua tables are similar.<|eor|><|sor|>I don't know whtat Lua does, but silently throwing information away without explicitly requested is generally bad design. Fine that you don't want me to use float keys, but then I should be forced to write an explicit cast to int or get an error otherwise.<|eor|><|sor|>> but silently throwing information away without explicitly requested is generally bad design
As I mentioned elsewhere, this may be a very useful feature for some applications. But it's not for everyone, I suppose.<|eor|><|sor|>It's almost like you're trying to frame this as a matter of opinion. Except, we're talking about what is reasonable to expect from a language, and there's a subtle difference. The key word being "reason".
If you'd like my opinion though, I think anyone who expects their data to be lost or transformed in a context like this has not had the fortune of using a properly designed language.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | SquireCD | l5z3k3 | <|sols|><|sot|>Good news but also lol<|eot|><|sol|>/r/PHP/comments/l5f4l7/the_tide_has_turned_php_manual_started_to_promote/<|eol|><|eols|><|endoftext|> | 52 |
lolphp | elcapitanoooo | gkxpflg | <|sols|><|sot|>Good news but also lol<|eot|><|sol|>/r/PHP/comments/l5f4l7/the_tide_has_turned_php_manual_started_to_promote/<|eol|><|sor|>The way PHP handles errors are appalling by all standards. Im not a fan of exceptions in the first place (because many misuse them as a control flow primitive), but in PHP its even worse.
A very common thing in PHP is encoding and decoding json, and its basically a nutcracker as you must call an external function to have any clue of possible errors.
Basically a rock-bottom approach in PHP to handle json would be something like:
$content = file_get_contents('lol.json');
if ($content === false) {
throw new Exception('lolphp');
}
$lol = json_decode($content);
$err = json_last_error();
if ($lol === null) {
throw new Exception('additional lol: '. $err);
}
// use $lol
Thats just appalling compared to anything really. Its really funny that PHP has come to this, after all its the year 2021.<|eor|><|sor|>To be honest, it is not *entire* PHP as can be made from your comment but rather *exception* from the rule.
Also, json_decode is able to throw exceptions since 7.3.
Regarding file_get_contents(), it throws a warning which doesn't stop the execution but PHP is moving towards making all errors into exceptions. For the moment you can use a simple error handler to convert the few remaining errors. Hence the actual code for your example is
$lol = json_decode(file_get_contents('lol.json'), false, 512, JSON_THROW_ON_ERROR);
eventually this mode will become default and the code will be just
$lol = json_decode(file_get_contents('lol.json'));<|eor|><|sor|>Yes, this is the typical PHP approach, just bolt on more params. This has been the way PHP has been trying to lipstick the broken design for years. Thats also why multiple php functions taking arguments like foo(true, true, 1, SOME_CONSTANT, false).<|eor|><|eols|><|endoftext|> | 13 |
lolphp | elcapitanoooo | gkxji6e | <|sols|><|sot|>Good news but also lol<|eot|><|sol|>/r/PHP/comments/l5f4l7/the_tide_has_turned_php_manual_started_to_promote/<|eol|><|sor|>The way PHP handles errors are appalling by all standards. Im not a fan of exceptions in the first place (because many misuse them as a control flow primitive), but in PHP its even worse.
A very common thing in PHP is encoding and decoding json, and its basically a nutcracker as you must call an external function to have any clue of possible errors.
Basically a rock-bottom approach in PHP to handle json would be something like:
$content = file_get_contents('lol.json');
if ($content === false) {
throw new Exception('lolphp');
}
$lol = json_decode($content);
$err = json_last_error();
if ($lol === null) {
throw new Exception('additional lol: '. $err);
}
// use $lol
Thats just appalling compared to anything really. Its really funny that PHP has come to this, after all its the year 2021.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | kksnicoh | gkxj9tw | <|sols|><|sot|>Good news but also lol<|eot|><|sol|>/r/PHP/comments/l5f4l7/the_tide_has_turned_php_manual_started_to_promote/<|eol|><|sor|>oh yea, PDO library error mode configuration makes the semantical behavior of the program completely different / useless.
but congratz on moving onto the future 2010<|eor|><|eols|><|endoftext|> | 11 |
lolphp | colshrapnel | gkxlq6e | <|sols|><|sot|>Good news but also lol<|eot|><|sol|>/r/PHP/comments/l5f4l7/the_tide_has_turned_php_manual_started_to_promote/<|eol|><|sor|>The way PHP handles errors are appalling by all standards. Im not a fan of exceptions in the first place (because many misuse them as a control flow primitive), but in PHP its even worse.
A very common thing in PHP is encoding and decoding json, and its basically a nutcracker as you must call an external function to have any clue of possible errors.
Basically a rock-bottom approach in PHP to handle json would be something like:
$content = file_get_contents('lol.json');
if ($content === false) {
throw new Exception('lolphp');
}
$lol = json_decode($content);
$err = json_last_error();
if ($lol === null) {
throw new Exception('additional lol: '. $err);
}
// use $lol
Thats just appalling compared to anything really. Its really funny that PHP has come to this, after all its the year 2021.<|eor|><|sor|>To be honest, it is not *entire* PHP as can be made from your comment but rather *exception* from the rule.
Also, json_decode is able to throw exceptions since 7.3.
Regarding file_get_contents(), it throws a warning which doesn't stop the execution but PHP is moving towards making all errors into exceptions. For the moment you can use a simple error handler to convert the few remaining errors. Hence the actual code for your example is
$lol = json_decode(file_get_contents('lol.json'), false, 512, JSON_THROW_ON_ERROR);
eventually this mode will become default and the code will be just
$lol = json_decode(file_get_contents('lol.json'));<|eor|><|eols|><|endoftext|> | 6 |
lolphp | shared-media | bfzpjp | <|sols|><|sot|>Thanks google news, we need more PHP topics<|eot|><|sol|>https://i.redd.it/qf3jywqc2st21.jpg<|eol|><|eols|><|endoftext|> | 51 |
lolphp | squiggleslash | elhql8r | <|sols|><|sot|>Thanks google news, we need more PHP topics<|eot|><|sol|>https://i.redd.it/qf3jywqc2st21.jpg<|eol|><|sor|>I'm surprised the list didn't also include 0, "0", false, "", and null.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | dotancohen | elhhk3w | <|sols|><|sot|>Thanks google news, we need more PHP topics<|eot|><|sol|>https://i.redd.it/qf3jywqc2st21.jpg<|eol|><|sor|>This is a lolgoogle, it has nothing to do with PHP.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | pilif | 787til | <|sols|><|sot|>Go home fputcsv() you're drunk<|eot|><|sol|>https://3v4l.org/LKkfW<|eol|><|eols|><|endoftext|> | 51 |
lolphp | SirClueless | dos7irn | <|sols|><|sot|>Go home fputcsv() you're drunk<|eot|><|sol|>https://3v4l.org/LKkfW<|eol|><|sor|>OK, so this is all documented incredibly poorly, and `escape_char` is not doing at all what you think it's doing. All it is doing is **searching the input string** for this character and printing this character and the one following as literals. [Literally the only thing it does](https://github.com/php/php-src/blob/d3bc8beb4ff9e00c3742ada32788239c3f7988e0/ext/standard/file.c#L1952) is suppress the doubling of `enclosure_char` if preceded by an `escape_char` in the input data.
Why? Who the fuck knows.
It was committed with a [woefully inadequate test](https://github.com/php/php-src/blob/PHP-7.2/ext/standard/tests/file/fputcsv_variation15.phpt) that only includes this escape char in 4 cases. The tests PHP documents as "Test fputcsv() : usage variations - with all parameters specified" [don't include this parameter](https://github.com/php/php-src/blob/6053987bc27e8dede37f437193a5cad448f99bce/ext/standard/tests/file/fputcsv_variation1.phpt#L58), and indeed you can find this out of date comment at the top of the file:
/*
Prototype: array fputcsv ( resource $handle , array $fields [, string $delimiter [, string $enclosure]]] );
Description: Format line as CSV and write to the file pointer
*/
# Story time!
OK, so it looks like a long time ago, PHP was hardcoded to use `\` as a special-case `escape_char`. Why? I don't know and [neither do the PHP developers](https://bugs.php.net/bug.php?id=43225) (see last comment). But it caused invalid CSV files in some cases when `\` was in the input. Some kind-hearted soul [fixed this in 2013](https://github.com/php/php-src/commit/9b5cb0e8059b1e8bec096067491ed8d75f878938).
But then he decided this fix wasn't good, "On second thoughts, while the behaviour _is_ broken, this isn't the right fix." [and reintroduced the bug shortly after](https://github.com/php/php-src/commit/c077074c1379b5faed386106fdbb53f5d17fd6e7).
[Bug 43225](https://bugs.php.net/bug.php?id=43225) remains open today.
...
Meanwhile, on a separate branch of the code, another kind-hearted person saw that `escape_char` was a hard-coded magical character and took offense. So he [exposed the parameter to users](https://github.com/php/php-src/commit/2139d2702d26e62f220f24e268d8ea1e09a9ee64) so that we can all generate broken CSV with whatever input character we want, instead of only being able to generate broken CSV files with `\` characters in the input.<|eor|><|eols|><|endoftext|> | 54 |
lolphp | pilif | dosba1h | <|sols|><|sot|>Go home fputcsv() you're drunk<|eot|><|sol|>https://3v4l.org/LKkfW<|eol|><|sor|>OK, so this is all documented incredibly poorly, and `escape_char` is not doing at all what you think it's doing. All it is doing is **searching the input string** for this character and printing this character and the one following as literals. [Literally the only thing it does](https://github.com/php/php-src/blob/d3bc8beb4ff9e00c3742ada32788239c3f7988e0/ext/standard/file.c#L1952) is suppress the doubling of `enclosure_char` if preceded by an `escape_char` in the input data.
Why? Who the fuck knows.
It was committed with a [woefully inadequate test](https://github.com/php/php-src/blob/PHP-7.2/ext/standard/tests/file/fputcsv_variation15.phpt) that only includes this escape char in 4 cases. The tests PHP documents as "Test fputcsv() : usage variations - with all parameters specified" [don't include this parameter](https://github.com/php/php-src/blob/6053987bc27e8dede37f437193a5cad448f99bce/ext/standard/tests/file/fputcsv_variation1.phpt#L58), and indeed you can find this out of date comment at the top of the file:
/*
Prototype: array fputcsv ( resource $handle , array $fields [, string $delimiter [, string $enclosure]]] );
Description: Format line as CSV and write to the file pointer
*/
# Story time!
OK, so it looks like a long time ago, PHP was hardcoded to use `\` as a special-case `escape_char`. Why? I don't know and [neither do the PHP developers](https://bugs.php.net/bug.php?id=43225) (see last comment). But it caused invalid CSV files in some cases when `\` was in the input. Some kind-hearted soul [fixed this in 2013](https://github.com/php/php-src/commit/9b5cb0e8059b1e8bec096067491ed8d75f878938).
But then he decided this fix wasn't good, "On second thoughts, while the behaviour _is_ broken, this isn't the right fix." [and reintroduced the bug shortly after](https://github.com/php/php-src/commit/c077074c1379b5faed386106fdbb53f5d17fd6e7).
[Bug 43225](https://bugs.php.net/bug.php?id=43225) remains open today.
...
Meanwhile, on a separate branch of the code, another kind-hearted person saw that `escape_char` was a hard-coded magical character and took offense. So he [exposed the parameter to users](https://github.com/php/php-src/commit/2139d2702d26e62f220f24e268d8ea1e09a9ee64) so that we can all generate broken CSV with whatever input character we want, instead of only being able to generate broken CSV files with `\` characters in the input.<|eor|><|soopr|>Amazing. Thank you.
After reading this I feel even more vindicated about posting this here. If this isnt a case for lolphp, I dont know what is. <|eoopr|><|eols|><|endoftext|> | 20 |
lolphp | SirClueless | dosc0lf | <|sols|><|sot|>Go home fputcsv() you're drunk<|eot|><|sol|>https://3v4l.org/LKkfW<|eol|><|sor|>OK, so this is all documented incredibly poorly, and `escape_char` is not doing at all what you think it's doing. All it is doing is **searching the input string** for this character and printing this character and the one following as literals. [Literally the only thing it does](https://github.com/php/php-src/blob/d3bc8beb4ff9e00c3742ada32788239c3f7988e0/ext/standard/file.c#L1952) is suppress the doubling of `enclosure_char` if preceded by an `escape_char` in the input data.
Why? Who the fuck knows.
It was committed with a [woefully inadequate test](https://github.com/php/php-src/blob/PHP-7.2/ext/standard/tests/file/fputcsv_variation15.phpt) that only includes this escape char in 4 cases. The tests PHP documents as "Test fputcsv() : usage variations - with all parameters specified" [don't include this parameter](https://github.com/php/php-src/blob/6053987bc27e8dede37f437193a5cad448f99bce/ext/standard/tests/file/fputcsv_variation1.phpt#L58), and indeed you can find this out of date comment at the top of the file:
/*
Prototype: array fputcsv ( resource $handle , array $fields [, string $delimiter [, string $enclosure]]] );
Description: Format line as CSV and write to the file pointer
*/
# Story time!
OK, so it looks like a long time ago, PHP was hardcoded to use `\` as a special-case `escape_char`. Why? I don't know and [neither do the PHP developers](https://bugs.php.net/bug.php?id=43225) (see last comment). But it caused invalid CSV files in some cases when `\` was in the input. Some kind-hearted soul [fixed this in 2013](https://github.com/php/php-src/commit/9b5cb0e8059b1e8bec096067491ed8d75f878938).
But then he decided this fix wasn't good, "On second thoughts, while the behaviour _is_ broken, this isn't the right fix." [and reintroduced the bug shortly after](https://github.com/php/php-src/commit/c077074c1379b5faed386106fdbb53f5d17fd6e7).
[Bug 43225](https://bugs.php.net/bug.php?id=43225) remains open today.
...
Meanwhile, on a separate branch of the code, another kind-hearted person saw that `escape_char` was a hard-coded magical character and took offense. So he [exposed the parameter to users](https://github.com/php/php-src/commit/2139d2702d26e62f220f24e268d8ea1e09a9ee64) so that we can all generate broken CSV with whatever input character we want, instead of only being able to generate broken CSV files with `\` characters in the input.<|eor|><|soopr|>Amazing. Thank you.
After reading this I feel even more vindicated about posting this here. If this isnt a case for lolphp, I dont know what is. <|eoopr|><|sor|>Yeah, no kidding. I think this is probably a security vulnerability.
You can print a CSV file that will execute the calculator program on your computer via Excel: https://3v4l.org/46IUc<|eor|><|eols|><|endoftext|> | 7 |
lolphp | yawkat | dorsr9l | <|sols|><|sot|>Go home fputcsv() you're drunk<|eot|><|sol|>https://3v4l.org/LKkfW<|eol|><|sor|>And knowing csv, this is probably valid in some obscure csv dialect.
Still pretty fucked up though.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | nyamsprod | dot65q5 | <|sols|><|sot|>Go home fputcsv() you're drunk<|eot|><|sol|>https://3v4l.org/LKkfW<|eol|><|sor|>OK, so this is all documented incredibly poorly, and `escape_char` is not doing at all what you think it's doing. All it is doing is **searching the input string** for this character and printing this character and the one following as literals. [Literally the only thing it does](https://github.com/php/php-src/blob/d3bc8beb4ff9e00c3742ada32788239c3f7988e0/ext/standard/file.c#L1952) is suppress the doubling of `enclosure_char` if preceded by an `escape_char` in the input data.
Why? Who the fuck knows.
It was committed with a [woefully inadequate test](https://github.com/php/php-src/blob/PHP-7.2/ext/standard/tests/file/fputcsv_variation15.phpt) that only includes this escape char in 4 cases. The tests PHP documents as "Test fputcsv() : usage variations - with all parameters specified" [don't include this parameter](https://github.com/php/php-src/blob/6053987bc27e8dede37f437193a5cad448f99bce/ext/standard/tests/file/fputcsv_variation1.phpt#L58), and indeed you can find this out of date comment at the top of the file:
/*
Prototype: array fputcsv ( resource $handle , array $fields [, string $delimiter [, string $enclosure]]] );
Description: Format line as CSV and write to the file pointer
*/
# Story time!
OK, so it looks like a long time ago, PHP was hardcoded to use `\` as a special-case `escape_char`. Why? I don't know and [neither do the PHP developers](https://bugs.php.net/bug.php?id=43225) (see last comment). But it caused invalid CSV files in some cases when `\` was in the input. Some kind-hearted soul [fixed this in 2013](https://github.com/php/php-src/commit/9b5cb0e8059b1e8bec096067491ed8d75f878938).
But then he decided this fix wasn't good, "On second thoughts, while the behaviour _is_ broken, this isn't the right fix." [and reintroduced the bug shortly after](https://github.com/php/php-src/commit/c077074c1379b5faed386106fdbb53f5d17fd6e7).
[Bug 43225](https://bugs.php.net/bug.php?id=43225) remains open today.
...
Meanwhile, on a separate branch of the code, another kind-hearted person saw that `escape_char` was a hard-coded magical character and took offense. So he [exposed the parameter to users](https://github.com/php/php-src/commit/2139d2702d26e62f220f24e268d8ea1e09a9ee64) so that we can all generate broken CSV with whatever input character we want, instead of only being able to generate broken CSV files with `\` characters in the input.<|eor|><|soopr|>Amazing. Thank you.
After reading this I feel even more vindicated about posting this here. If this isnt a case for lolphp, I dont know what is. <|eoopr|><|sor|>Yeah, no kidding. I think this is probably a security vulnerability.
You can print a CSV file that will execute the calculator program on your computer via Excel: https://3v4l.org/46IUc<|eor|><|sor|>well technically I would call this a spreadsheetlol. The first rule in any computer programming system is don't trust the user input. Instead of fixing spreadsheet programs which perform actions on user input without making any descent filtering first you are assuming that CSV which predates spreadsheet programs should be fixed for something which is out of its scope to begin with<|eor|><|eols|><|endoftext|> | 6 |
lolphp | pilif | dors052 | <|sols|><|sot|>Go home fputcsv() you're drunk<|eot|><|sol|>https://3v4l.org/LKkfW<|eol|><|sor|>Two questions:
1. Why is the first column getting enclosed when it doesn't need to be?
2. Aren't single quotes supposed to not evaluate escape sequences? What I mean is, shouldn't the last line start with: using \\\\ ...<|eor|><|soopr|>> Why is the first column getting enclosed when it doesn't need to be?
good question. PHP always encloses in quotes which is fine I guess.
> Aren't single quotes supposed to not evaluate escape sequences
Single quoted strings still evaluate two \\-sequences: \' to escape the single quote and \\\\ to escape the \<|eoopr|><|eols|><|endoftext|> | 5 |
lolphp | SirClueless | dotlw0x | <|sols|><|sot|>Go home fputcsv() you're drunk<|eot|><|sol|>https://3v4l.org/LKkfW<|eol|><|sor|>OK, so this is all documented incredibly poorly, and `escape_char` is not doing at all what you think it's doing. All it is doing is **searching the input string** for this character and printing this character and the one following as literals. [Literally the only thing it does](https://github.com/php/php-src/blob/d3bc8beb4ff9e00c3742ada32788239c3f7988e0/ext/standard/file.c#L1952) is suppress the doubling of `enclosure_char` if preceded by an `escape_char` in the input data.
Why? Who the fuck knows.
It was committed with a [woefully inadequate test](https://github.com/php/php-src/blob/PHP-7.2/ext/standard/tests/file/fputcsv_variation15.phpt) that only includes this escape char in 4 cases. The tests PHP documents as "Test fputcsv() : usage variations - with all parameters specified" [don't include this parameter](https://github.com/php/php-src/blob/6053987bc27e8dede37f437193a5cad448f99bce/ext/standard/tests/file/fputcsv_variation1.phpt#L58), and indeed you can find this out of date comment at the top of the file:
/*
Prototype: array fputcsv ( resource $handle , array $fields [, string $delimiter [, string $enclosure]]] );
Description: Format line as CSV and write to the file pointer
*/
# Story time!
OK, so it looks like a long time ago, PHP was hardcoded to use `\` as a special-case `escape_char`. Why? I don't know and [neither do the PHP developers](https://bugs.php.net/bug.php?id=43225) (see last comment). But it caused invalid CSV files in some cases when `\` was in the input. Some kind-hearted soul [fixed this in 2013](https://github.com/php/php-src/commit/9b5cb0e8059b1e8bec096067491ed8d75f878938).
But then he decided this fix wasn't good, "On second thoughts, while the behaviour _is_ broken, this isn't the right fix." [and reintroduced the bug shortly after](https://github.com/php/php-src/commit/c077074c1379b5faed386106fdbb53f5d17fd6e7).
[Bug 43225](https://bugs.php.net/bug.php?id=43225) remains open today.
...
Meanwhile, on a separate branch of the code, another kind-hearted person saw that `escape_char` was a hard-coded magical character and took offense. So he [exposed the parameter to users](https://github.com/php/php-src/commit/2139d2702d26e62f220f24e268d8ea1e09a9ee64) so that we can all generate broken CSV with whatever input character we want, instead of only being able to generate broken CSV files with `\` characters in the input.<|eor|><|soopr|>Amazing. Thank you.
After reading this I feel even more vindicated about posting this here. If this isnt a case for lolphp, I dont know what is. <|eoopr|><|sor|>Yeah, no kidding. I think this is probably a security vulnerability.
You can print a CSV file that will execute the calculator program on your computer via Excel: https://3v4l.org/46IUc<|eor|><|sor|>well technically I would call this a spreadsheetlol. The first rule in any computer programming system is don't trust the user input. Instead of fixing spreadsheet programs which perform actions on user input without making any descent filtering first you are assuming that CSV which predates spreadsheet programs should be fixed for something which is out of its scope to begin with<|eor|><|sor|>A bit of both I'd say. It's a PHP problem that user-supplied data can break out of its cell and insert whatever unquoted data it wants to into a CSV (problematic even if you don't use it to execute code). It's a spreadsheet problem that Excel evaluates formulas when it imports from a CSV.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | jesseschalken | 5htz6l | <|sols|><|sot|>Automatic string->int conversion for string literals, but not for variables containing strings<|eot|><|sol|>https://3v4l.org/id5OA<|eol|><|eols|><|endoftext|> | 51 |
lolphp | sproingie | db30kfi | <|sols|><|sot|>Automatic string->int conversion for string literals, but not for variables containing strings<|eot|><|sol|>https://3v4l.org/id5OA<|eol|><|sor|>PHP's confused array implementation strikes again. It is worth noting that HHVM (and therefore Hack) gets it right.<|eor|><|eols|><|endoftext|> | 21 |
lolphp | the_alias_of_andrea | db3m5l0 | <|sols|><|sot|>Automatic string->int conversion for string literals, but not for variables containing strings<|eot|><|sol|>https://3v4l.org/id5OA<|eol|><|sor|>It's a known issue that I'd like to fix. At compile-time, `$foo["123"]` is rewritten to `$foo[123]`. This would be a completely safe and transparent optimisation, except `ArrayAccess` exists.
Maybe it'll be removed eventually.<|eor|><|eols|><|endoftext|> | 16 |
lolphp | the_alias_of_andrea | db3m6ld | <|sols|><|sot|>Automatic string->int conversion for string literals, but not for variables containing strings<|eot|><|sol|>https://3v4l.org/id5OA<|eol|><|sor|>PHP's confused array implementation strikes again. It is worth noting that HHVM (and therefore Hack) gets it right.<|eor|><|sor|>HHVM lacks this particular broken optimisation. It still has arrays, if you want to complain about those.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | suspiciously_calm | db44e4v | <|sols|><|sot|>Automatic string->int conversion for string literals, but not for variables containing strings<|eot|><|sol|>https://3v4l.org/id5OA<|eol|><|sor|>*And of course* the behavior changes within a major version number.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | jesseschalken | db7k3ms | <|sols|><|sot|>Automatic string->int conversion for string literals, but not for variables containing strings<|eot|><|sol|>https://3v4l.org/id5OA<|eol|><|sor|>PHP's confused array implementation strikes again. It is worth noting that HHVM (and therefore Hack) gets it right.<|eor|><|sor|>HHVM lacks this particular broken optimisation. It still has arrays, if you want to complain about those.<|eor|><|sor|>Does it have the stupid mix of array and hash? Two totally different data structures with totally different performance characteristics?
If it does it is as idiotic as PHP.<|eor|><|soopr|>HHVM includes PHP arrays along with their idiotic semantics for compatibility, but also includes three new types `vec`, `dict` and `keyset` to migrate your code to, which have the normal and sane semantics and performance you'd expect. It also has `Vector`, `Map` and `Set` classes.<|eoopr|><|eols|><|endoftext|> | 6 |
lolphp | Takeoded | 4msozr | <|sols|><|sot|>linkinfo returns 0 or false or -1 for error<|eot|><|sol|>http://php.net/manual/en/function.linkinfo.php<|eol|><|eols|><|endoftext|> | 52 |
lolphp | Various_Pickles | d3yglbn | <|sols|><|sot|>linkinfo returns 0 or false or -1 for error<|eot|><|sol|>http://php.net/manual/en/function.linkinfo.php<|eol|><|sor|>Now all it needs to do is:
* Only report errors in a way that's accessible via manually calling linkinfo_error()
* Read all of its associated internal state directly from (the first) php.ini
* Assume that all callers aren't using UTF-8
* ... are in the same locale
* ... are in the same timezone
* ... are in the same thread
then it will have attained the state of PHP Nirvana.
The manscorpions native to the Plane that PHP originates from will praise your name.<|eor|><|eols|><|endoftext|> | 28 |
lolphp | nikic | d3ygmx9 | <|sols|><|sot|>linkinfo returns 0 or false or -1 for error<|eot|><|sol|>http://php.net/manual/en/function.linkinfo.php<|eol|><|sor|>From a quick glance at the code this looks like a documentation error. It's either `false` or `-1`, but not `0`.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | garagedragon | d3ygoxe | <|sols|><|sot|>linkinfo returns 0 or false or -1 for error<|eot|><|sol|>http://php.net/manual/en/function.linkinfo.php<|eol|><|sor|>The downvotes on the comment are the icing on the cake.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | squiggleslash | d3ytx29 | <|sols|><|sot|>linkinfo returns 0 or false or -1 for error<|eot|><|sol|>http://php.net/manual/en/function.linkinfo.php<|eol|><|sor|>From a quick glance at the code this looks like a documentation error. It's either `false` or `-1`, but not `0`.<|eor|><|sor|>Maybe it should return "", or even better "0"...<|eor|><|eols|><|endoftext|> | 10 |
lolphp | Deviltry1 | d3z8q59 | <|sols|><|sot|>linkinfo returns 0 or false or -1 for error<|eot|><|sol|>http://php.net/manual/en/function.linkinfo.php<|eol|><|sor|>From a quick glance at the code this looks like a documentation error. It's either `false` or `-1`, but not `0`.<|eor|><|sor|>Maybe it should return "", or even better "0"...<|eor|><|sor|>"whoopsies"<|eor|><|eols|><|endoftext|> | 6 |
lolphp | RainOnYourTirade | 4mame1 | <|sols|><|sot|>Oh boy, I wonder what this function does<|eot|><|sol|>http://i.imgur.com/RffXApG.jpg<|eol|><|eols|><|endoftext|> | 51 |
lolphp | RainOnYourTirade | d3tx5n7 | <|sols|><|sot|>Oh boy, I wonder what this function does<|eot|><|sol|>http://i.imgur.com/RffXApG.jpg<|eol|><|soopr|>Actually, most of Imagick is pretty sparesly documented, with some functions going as far as to have the warning:
>This function is currently not documented; only its argument list is available.
Quality libraries for a quality language /s<|eoopr|><|eols|><|endoftext|> | 19 |
lolphp | duskwuff | d3tyxgr | <|sols|><|sot|>Oh boy, I wonder what this function does<|eot|><|sol|>http://i.imgur.com/RffXApG.jpg<|eol|><|soopr|>Actually, most of Imagick is pretty sparesly documented, with some functions going as far as to have the warning:
>This function is currently not documented; only its argument list is available.
Quality libraries for a quality language /s<|eoopr|><|sor|>That being said this is at least as much Imagemagick's fault as PHP's. It's a terrible image library. (As all the recent vulnerabilities may have reminded you.)<|eor|><|eols|><|endoftext|> | 15 |
lolphp | duskwuff | d3tzndw | <|sols|><|sot|>Oh boy, I wonder what this function does<|eot|><|sol|>http://i.imgur.com/RffXApG.jpg<|eol|><|soopr|>Actually, most of Imagick is pretty sparesly documented, with some functions going as far as to have the warning:
>This function is currently not documented; only its argument list is available.
Quality libraries for a quality language /s<|eoopr|><|sor|>That being said this is at least as much Imagemagick's fault as PHP's. It's a terrible image library. (As all the recent vulnerabilities may have reminded you.)<|eor|><|soopr|>Oh definitely, that was part of the reason I was checking it out. The naming schemes are pretty bad and evidently the library itself is a disaster.<|eoopr|><|sor|>The worst part is, though all the other image libraries I've worked with have been at least as bad, if not worse. As far as I can tell, there are **no** good open-source image manipulation libraries.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | Danack | d3ubs9l | <|sols|><|sot|>Oh boy, I wonder what this function does<|eot|><|sol|>http://i.imgur.com/RffXApG.jpg<|eol|><|soopr|>Actually, most of Imagick is pretty sparesly documented, with some functions going as far as to have the warning:
>This function is currently not documented; only its argument list is available.
Quality libraries for a quality language /s<|eoopr|><|sor|>> most of Imagick is pretty sparesly documented,
Really? I thought there were only 3 entries that aren't documented ......I actually did a huge amount of work to go through and added documentation to the vast majority of the functions, and also include examples for them,
Anyway feel free to help out with the manual if you use the library. There is an edit button on each page of the manual.
<|eor|><|eols|><|endoftext|> | 8 |
lolphp | RainOnYourTirade | d3tz4rd | <|sols|><|sot|>Oh boy, I wonder what this function does<|eot|><|sol|>http://i.imgur.com/RffXApG.jpg<|eol|><|soopr|>Actually, most of Imagick is pretty sparesly documented, with some functions going as far as to have the warning:
>This function is currently not documented; only its argument list is available.
Quality libraries for a quality language /s<|eoopr|><|sor|>That being said this is at least as much Imagemagick's fault as PHP's. It's a terrible image library. (As all the recent vulnerabilities may have reminded you.)<|eor|><|soopr|>Oh definitely, that was part of the reason I was checking it out. The naming schemes are pretty bad and evidently the library itself is a disaster.<|eoopr|><|eols|><|endoftext|> | 8 |
lolphp | RainOnYourTirade | d3u09n6 | <|sols|><|sot|>Oh boy, I wonder what this function does<|eot|><|sol|>http://i.imgur.com/RffXApG.jpg<|eol|><|soopr|>Actually, most of Imagick is pretty sparesly documented, with some functions going as far as to have the warning:
>This function is currently not documented; only its argument list is available.
Quality libraries for a quality language /s<|eoopr|><|sor|>That being said this is at least as much Imagemagick's fault as PHP's. It's a terrible image library. (As all the recent vulnerabilities may have reminded you.)<|eor|><|soopr|>Oh definitely, that was part of the reason I was checking it out. The naming schemes are pretty bad and evidently the library itself is a disaster.<|eoopr|><|sor|>The worst part is, though all the other image libraries I've worked with have been at least as bad, if not worse. As far as I can tell, there are **no** good open-source image manipulation libraries.<|eor|><|soopr|>Well, however bad image-processing libraries are, they still beat editing hundreds of images by hand. I just wonder why none of these libraries are actually designed right.<|eoopr|><|eols|><|endoftext|> | 8 |
lolphp | Danack | d3ubobf | <|sols|><|sot|>Oh boy, I wonder what this function does<|eot|><|sol|>http://i.imgur.com/RffXApG.jpg<|eol|><|sor|>Imagick is much better than the GD library that PHP ships with by default for some reason. It is strange that it's so undocumented though.<|eor|><|sor|>> It is strange that it's so undocumented though.
Writing documentation is actually way more painful than supporting the library.
And way less interesting than making examples. Almost all of the library has examples at: http://phpimagick.com/
Oh, in this case it's just a 'typo' - the actual function is documented if you click it's link: http://php.net/manual/en/imagick.subimagematch.php
> Searches for a subimage in the current image and returns a similarity image such that an exact match location is completely white and if none of the pixels match, black, otherwise some gray level in-between. You can also pass in the optional parameters bestMatch and similarity. After calling the function similarity will be set to the 'score' of the similarity between the subimage and the matching position in the larger image, bestMatch will contain an associative array with elements x, y, width, height that describe the matching region.
<|eor|><|eols|><|endoftext|> | 7 |
lolphp | emilvikstrom | d3u390s | <|sols|><|sot|>Oh boy, I wonder what this function does<|eot|><|sol|>http://i.imgur.com/RffXApG.jpg<|eol|><|sor|>Imagick is much better than the GD library that PHP ships with by default for some reason. It is strange that it's so undocumented though.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | Danack | d3ubvlm | <|sols|><|sot|>Oh boy, I wonder what this function does<|eot|><|sol|>http://i.imgur.com/RffXApG.jpg<|eol|><|soopr|>Actually, most of Imagick is pretty sparesly documented, with some functions going as far as to have the warning:
>This function is currently not documented; only its argument list is available.
Quality libraries for a quality language /s<|eoopr|><|sor|>That being said this is at least as much Imagemagick's fault as PHP's. It's a terrible image library. (As all the recent vulnerabilities may have reminded you.)<|eor|><|soopr|>Oh definitely, that was part of the reason I was checking it out. The naming schemes are pretty bad and evidently the library itself is a disaster.<|eoopr|><|sor|>The worst part is, though all the other image libraries I've worked with have been at least as bad, if not worse. As far as I can tell, there are **no** good open-source image manipulation libraries.<|eor|><|sor|>http://www.graphicsmagick.org ?<|eor|><|sor|>The guy who forked it isn't really that responsive to problems with it......and there are a significant number of issues with the library, particularly with animated gifs.
e.g. https://github.com/vitoc/gmagick/issues/18#issuecomment-168723588
> I've looked into this and it seems it need to be reported upstream at http://sourceforge.net/p/graphicsmagick/bugs/ as the behaviour GraphicsMagick has for addImage is just fundamentally wrong.
> When doing MagickAddImage( MagickWand *wand, const MagickWand *add_wand );
> if the wand is empty, the add_wand will not be added.
> if the wand contains one image, the add_wand will be added before that image.
> if the wand contains more than one image, the add_wand will be added after those images.
If all you are doing is resizing images, then GraphicsMagick/Gmagick may be usable for you. For anything that does other image manipulation......as not good as it is, ImageMagick is better.
<|eor|><|eols|><|endoftext|> | 6 |
lolphp | iopq | 4eeklg | <|sols|><|sot|>When errors don't help<|eot|><|sol|>http://i.imgur.com/Uv2Wo3u.png<|eol|><|eols|><|endoftext|> | 48 |
lolphp | edwardly | d1zkbfu | <|sols|><|sot|>When errors don't help<|eot|><|sol|>http://i.imgur.com/Uv2Wo3u.png<|eol|><|sor|>It kinda looks like you tried to "type hint" to class `string`, attempting to hint the scalar type string - available in PHP7. Is that what happened here?
Assuming you saw this in the docs - http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
Are you using PHP7?<|eor|><|eols|><|endoftext|> | 15 |
lolphp | the_alias_of_andrea | d1zm26h | <|sols|><|sot|>When errors don't help<|eot|><|sol|>http://i.imgur.com/Uv2Wo3u.png<|eol|><|sor|>It's a slightly confusing error message, but what it means is you have a type declaration requiring an object that is an instance of a class named `string`, whereas what you've given it is a string, the basic type.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | edwardly | d1zlmxh | <|sols|><|sot|>When errors don't help<|eot|><|sol|>http://i.imgur.com/Uv2Wo3u.png<|eol|><|sor|>It kinda looks like you tried to "type hint" to class `string`, attempting to hint the scalar type string - available in PHP7. Is that what happened here?
Assuming you saw this in the docs - http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
Are you using PHP7?<|eor|><|soopr|>it's fixed in PHP7, AFAIK<|eoopr|><|sor|>Less fixed and more that it wasn't a feature until then.
Definitely agree that the error message is confusing.
I wonder if there could have been ways to redefine the error message to make it clearer? However, there's similar issues in other languages where there is shared terminology.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | jacybear | d20cyhr | <|sols|><|sot|>When errors don't help<|eot|><|sol|>http://i.imgur.com/Uv2Wo3u.png<|eol|><|sor|>It's a slightly confusing error message, but what it means is you have a type declaration requiring an object that is an instance of a class named `string`, whereas what you've given it is a string, the basic type.<|eor|><|sor|>Anybody who names a class `string` should be hanged.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | poizan42 | 19s4rb | <|sols|><|sot|>Impossible to comment a line with a string out when it contains "?>" (x-post from r/programming)<|eot|><|sol|>http://stackoverflow.com/q/15219815/1288<|eol|><|eols|><|endoftext|> | 51 |
lolphp | farsightxr20 | c8qtcw7 | <|sols|><|sot|>Impossible to comment a line with a string out when it contains "?>" (x-post from r/programming)<|eot|><|sol|>http://stackoverflow.com/q/15219815/1288<|eol|><|sor|>By the looks of it, you _can_ use `/* ... */` to comment out a line containing a closing tag; it just so happened that OP also had `*/` in his regex.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | the_alias_of_andrea | 3vy6vf | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|eols|><|endoftext|> | 53 |
lolphp | Jonny_Axehandle | cxrwcip | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|sor|>Should be a sidebar item<|eor|><|eols|><|endoftext|> | 23 |
lolphp | the_alias_of_andrea | cxs5h9w | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|sor|>I wonder how many of these are no longer an issue in PHP7, seeing as how its compiler has been rewritten and uses an AST.<|eor|><|soopr|>The lexer hasn't been rewritten, the compiler has.
Anyway, the only parsing thing that no longer fully applies to PHP 7 is \#31, because I fixed it.<|eoopr|><|eols|><|endoftext|> | 16 |
lolphp | the_alias_of_andrea | cxrr9rd | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|sor|>I've got one too:
* mpty` doesn't work on function return values, but only on variables/array items
For example, this won't work:
if(empty(trim($x)) $blank = true;
> Fatal error: Can't use function return value in write context
Where the hell does it see a "write context"?<|eor|><|soopr|>> mpty`
You need to press space after ` ;)
> For example, this won't work:
> if(empty(trim($x)) $blank = true;
It will in newer PHP versions.
> Where the hell does it see a "write context"?
It's what C would call an "lval", a thing you can put on the left-hand side of an `=` or use with `&`. `empty()` is like `isset()`, it checks if variables exist as well as doing a null (in `isset()`'s case) or falsiness (in `empty()`'s case) check.
In modern PHP versions you can also use it with non-variables, but this is rather pointless since you could simply do `if (!trim($x))`.<|eoopr|><|eols|><|endoftext|> | 14 |
lolphp | bart2019 | cxrqtg8 | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|sor|>I've got one too:
* mpty` doesn't work on function return values, but only on variables/array items
For example, this won't work:
if(empty(trim($x)) $blank = true;
> Fatal error: Can't use function return value in write context
Where the hell does it see a "write context"?<|eor|><|eols|><|endoftext|> | 13 |
lolphp | beerdude26 | cxsgkix | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|sor|>I've got one too:
* mpty` doesn't work on function return values, but only on variables/array items
For example, this won't work:
if(empty(trim($x)) $blank = true;
> Fatal error: Can't use function return value in write context
Where the hell does it see a "write context"?<|eor|><|sor|>empty('0') === TRUE
That fucked with form validation (checkboxes) in Drupal big time<|eor|><|eols|><|endoftext|> | 11 |
lolphp | BilgeXA | cxs45jy | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|sor|>Not being able to override private members is a sadness? No, actually it is pretty standard.<|eor|><|sor|>Moreover, the author cites mocking as a reason for overriding private methods. I believe that calls into question the author's competency with programming in general. Testing is about testing the public interface of an object, not its internals. If you need to test many private methods of a class it tends to hint that your class is doing too much and there's another class locked inside the private methods, crying to get out.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | Schmittfried | cxso4x6 | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|sor|>Not being able to override private members is a sadness? No, actually it is pretty standard.<|eor|><|sor|>Moreover, the author cites mocking as a reason for overriding private methods. I believe that calls into question the author's competency with programming in general. Testing is about testing the public interface of an object, not its internals. If you need to test many private methods of a class it tends to hint that your class is doing too much and there's another class locked inside the private methods, crying to get out.<|eor|><|sor|>> I believe that calls into question the author's competency with programming in general.
Wow, seriously? I realize this is an intentionally elitist subreddit, but you're letting your elitism go to your head here.<|eor|><|sor|>One can definitely say people who want to override private members didn't understand the concept of encapsulation.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | Schmittfried | cxrww4y | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|sor|>Not being able to override private members is a sadness? No, actually it is pretty standard.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | coredumperror | cxs9das | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|sor|>Not being able to override private members is a sadness? No, actually it is pretty standard.<|eor|><|sor|>Moreover, the author cites mocking as a reason for overriding private methods. I believe that calls into question the author's competency with programming in general. Testing is about testing the public interface of an object, not its internals. If you need to test many private methods of a class it tends to hint that your class is doing too much and there's another class locked inside the private methods, crying to get out.<|eor|><|sor|>> I believe that calls into question the author's competency with programming in general.
Wow, seriously? I realize this is an intentionally elitist subreddit, but you're letting your elitism go to your head here.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | squiggleslash | cxvp4rf | <|sols|><|sot|>PHP Sadness<|eot|><|sol|>http://phpsadness.com<|eol|><|sor|>I've got one too:
* mpty` doesn't work on function return values, but only on variables/array items
For example, this won't work:
if(empty(trim($x)) $blank = true;
> Fatal error: Can't use function return value in write context
Where the hell does it see a "write context"?<|eor|><|sor|>Just a word of advice - you probably never want to use empty() on strings ever. empty() on strings is functionally the same as "((value)==0)". So null, "", and "0" all evaluate to true. Yeah, "0" included.
<|eor|><|eols|><|endoftext|> | 6 |
lolphp | volnix | 2g3ziq | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|eols|><|endoftext|> | 53 |
lolphp | Muchoz | ckffu55 | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>Better use === then.<|eor|><|eols|><|endoftext|> | 16 |
lolphp | iopq | ckfssjq | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>Just because 0 == '0' doesn't mean that '0' == X where 0 == X
http://3v4l.org/7gslD<|eor|><|sor|>Unlike regular equality, php equality isn't transitive. `true == "php" == 0 == false`
Sometimes I wonder why php even keeps `==` around.<|eor|><|sor|>Because it's a fast and easy way to compare straightforward data w/o the need of converting variables back and forth. No convert.ToDouble['variable'] or anything like that needed first (and then back to a string when you're done).
It saves steps, particularly when you have data that switches back and forth a lot or there's text that contains #s you want to use in PHP code.
<|eor|><|sor|>Yeah, and when you do
if (strcmp($password,$_POST["password"]) == 0)
you just have to pass `submit.php?password[]=a` which will make `$_POST["password"]` an ARRAY because of how convenient PHP is
then the strcmp will give you an error, but it will also be equal to zero AND IT WON'T STOP EXECUTING THE SCRIPT so it will let you into the site
you literally have to make a specific effort not to get fucked over<|eor|><|eols|><|endoftext|> | 15 |
lolphp | raziel2p | ckff01b | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>Just because 0 == '0' doesn't mean that '0' == X where 0 == X
http://3v4l.org/7gslD<|eor|><|eols|><|endoftext|> | 14 |
lolphp | iopq | ckfw94d | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>Just because 0 == '0' doesn't mean that '0' == X where 0 == X
http://3v4l.org/7gslD<|eor|><|sor|>Unlike regular equality, php equality isn't transitive. `true == "php" == 0 == false`
Sometimes I wonder why php even keeps `==` around.<|eor|><|sor|>Because it's a fast and easy way to compare straightforward data w/o the need of converting variables back and forth. No convert.ToDouble['variable'] or anything like that needed first (and then back to a string when you're done).
It saves steps, particularly when you have data that switches back and forth a lot or there's text that contains #s you want to use in PHP code.
<|eor|><|sor|>Yeah, and when you do
if (strcmp($password,$_POST["password"]) == 0)
you just have to pass `submit.php?password[]=a` which will make `$_POST["password"]` an ARRAY because of how convenient PHP is
then the strcmp will give you an error, but it will also be equal to zero AND IT WON'T STOP EXECUTING THE SCRIPT so it will let you into the site
you literally have to make a specific effort not to get fucked over<|eor|><|sor|>Wait, what?
Just do:
if (($_POST["password"] != '') && ($_POST["password"] == $password)) {
// Password matches and do rest of logged-in stuff
}
else {
echo "Your password is empty and/or doesn't match. Try again.";
}
The POST value cannot be empty, so there's no way for the IF check to pass if that is missing.
And don't use Boolean or strcmp stuff on the variables for this. Just straight up compare the values once you know a POST value has been submitted. No need for arrays either.
Although for passwords we would be likely sanitizing/encrypting the POST value before comparison [not shown].
Not sure why you are making this overly complicated. KISS<|eor|><|sor|>oh, you wanted to hash the password?
if (md5($password) == $hash) {
print "Allowed!\n";
}
too bad if the password is `ximaz` its md5 hash is `61529519452809720693702583126814` it will match anything that hashes to `6152951945280972...` and will ignore the rest of the numbers because of running out of numeric precision because it uses the double data type to compare those two strings
yes, really<|eor|><|eols|><|endoftext|> | 14 |
lolphp | PasswordIsntHAMSTER | ckfjqx8 | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>Intransitive equality, so fucking stupid<|eor|><|eols|><|endoftext|> | 13 |
lolphp | ismtrn | ckfmwgh | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>>but only sometimes
No. `0 == '0'` is always true. You've used `in_array` to confuse the matter but you're comparing something totally different:
var_dump(0 == 'foo'); // true (numeric comparison)
var_dump('0' == 'foo'); // false (string comparison)<|eor|><|sor|>He is assuming transitivity, which is very reasonable. Who wouldn't expect equals to be an equivalence relation?<|eor|><|eols|><|endoftext|> | 13 |
lolphp | iopq | ckfwxhv | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>Just because 0 == '0' doesn't mean that '0' == X where 0 == X
http://3v4l.org/7gslD<|eor|><|sor|>Unlike regular equality, php equality isn't transitive. `true == "php" == 0 == false`
Sometimes I wonder why php even keeps `==` around.<|eor|><|sor|>Because it's a fast and easy way to compare straightforward data w/o the need of converting variables back and forth. No convert.ToDouble['variable'] or anything like that needed first (and then back to a string when you're done).
It saves steps, particularly when you have data that switches back and forth a lot or there's text that contains #s you want to use in PHP code.
<|eor|><|sor|>Yeah, and when you do
if (strcmp($password,$_POST["password"]) == 0)
you just have to pass `submit.php?password[]=a` which will make `$_POST["password"]` an ARRAY because of how convenient PHP is
then the strcmp will give you an error, but it will also be equal to zero AND IT WON'T STOP EXECUTING THE SCRIPT so it will let you into the site
you literally have to make a specific effort not to get fucked over<|eor|><|sor|>Wait, what?
Just do:
if (($_POST["password"] != '') && ($_POST["password"] == $password)) {
// Password matches and do rest of logged-in stuff
}
else {
echo "Your password is empty and/or doesn't match. Try again.";
}
The POST value cannot be empty, so there's no way for the IF check to pass if that is missing.
And don't use Boolean or strcmp stuff on the variables for this. Just straight up compare the values once you know a POST value has been submitted. No need for arrays either.
Although for passwords we would be likely sanitizing/encrypting the POST value before comparison [not shown].
Not sure why you are making this overly complicated. KISS<|eor|><|sor|>oh, you wanted to hash the password?
if (md5($password) == $hash) {
print "Allowed!\n";
}
too bad if the password is `ximaz` its md5 hash is `61529519452809720693702583126814` it will match anything that hashes to `6152951945280972...` and will ignore the rest of the numbers because of running out of numeric precision because it uses the double data type to compare those two strings
yes, really<|eor|><|sor|>I use functions that encrypt passwords as alphanumeric strings before any comparisons are made, so I don't encounter the issue you do.
But doesn't freakin' C# have the same issue with Double precision loss, meaning you gotta be very careful about using it and Decimal?
I'm not saying you're wrong in hating PHP, I'm just saying I don't approach passwords and security the same way you do. There isn't just one way to create a log-in system.<|eor|><|sor|>`ximaz` got md5 hashed to 61529519452809720693702583126814
md5 is hexadecimal, but that means some hashes are also valid decimal numbers
and no, C# doesn't have this issue because it compares strings as strings, not doubles
see my code, both of those things were STRINGS<|eor|><|eols|><|endoftext|> | 9 |
lolphp | iopq | ckfxi1y | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>Because it's a fast and easy way to compare straightforward data w/o the need of converting variables back and forth. No convert.ToDouble['variable'] or anything like that needed first (and then back to a string when you're done).
It saves steps, particularly when you have data that switches back and forth a lot or there's text that contains #s you want to use in PHP code.
<|eor|><|sor|>Yeah, and when you do
if (strcmp($password,$_POST["password"]) == 0)
you just have to pass `submit.php?password[]=a` which will make `$_POST["password"]` an ARRAY because of how convenient PHP is
then the strcmp will give you an error, but it will also be equal to zero AND IT WON'T STOP EXECUTING THE SCRIPT so it will let you into the site
you literally have to make a specific effort not to get fucked over<|eor|><|sor|>Wait, what?
Just do:
if (($_POST["password"] != '') && ($_POST["password"] == $password)) {
// Password matches and do rest of logged-in stuff
}
else {
echo "Your password is empty and/or doesn't match. Try again.";
}
The POST value cannot be empty, so there's no way for the IF check to pass if that is missing.
And don't use Boolean or strcmp stuff on the variables for this. Just straight up compare the values once you know a POST value has been submitted. No need for arrays either.
Although for passwords we would be likely sanitizing/encrypting the POST value before comparison [not shown].
Not sure why you are making this overly complicated. KISS<|eor|><|sor|>oh, you wanted to hash the password?
if (md5($password) == $hash) {
print "Allowed!\n";
}
too bad if the password is `ximaz` its md5 hash is `61529519452809720693702583126814` it will match anything that hashes to `6152951945280972...` and will ignore the rest of the numbers because of running out of numeric precision because it uses the double data type to compare those two strings
yes, really<|eor|><|sor|>I use functions that encrypt passwords as alphanumeric strings before any comparisons are made, so I don't encounter the issue you do.
But doesn't freakin' C# have the same issue with Double precision loss, meaning you gotta be very careful about using it and Decimal?
I'm not saying you're wrong in hating PHP, I'm just saying I don't approach passwords and security the same way you do. There isn't just one way to create a log-in system.<|eor|><|sor|>`ximaz` got md5 hashed to 61529519452809720693702583126814
md5 is hexadecimal, but that means some hashes are also valid decimal numbers
and no, C# doesn't have this issue because it compares strings as strings, not doubles
see my code, both of those things were STRINGS<|eor|><|sor|>Well, like I said I use encryption functions that do all their steps and then spit out a string used for comparison, and it definitely is not anything other than a straightforward string.
The md5() bit seems to be the weak point in your example. Just add that to the list of things that doesn't work well in PHP. Find other solutions and re-use those vs. relying on built-in stuff.
I'm not saying PHP is ideal or even not stupid at times, but it's everywhere and gets the job done for small-/mid-size projects. I wouldn't use it for anything mission critical where lives depended on it.<|eor|><|sor|>Again, the vulnerability is the fact that a "straightforward string" could actually be a valid number which will be coerced to a double. There is no such thing as a "straightforward string" in php unless you use `===`.
I'm a professional PHP developer and PHP definitely prevents me from being productive
starting from the fact that I can't look shit up in my IDE because everything is stringly typed and properties just get generated by strings
and of course the typos in variable names lead to subtle bugs because those variables just get initialized to 0
I do think it's OK for scripts under 1kloc, but that's about it<|eor|><|eols|><|endoftext|> | 9 |
lolphp | iopq | ckfsghk | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>Better use === then.<|eor|><|sor|>Is this so hard for people to understand? Wow. Again and again, people freak out over ===.<|eor|><|sor|>because you have to do `in_array($a, $b, true)`
so you have special versions of functions that do strict comparisons that you have to memorize where you put the "strict mode" argument in<|eor|><|eols|><|endoftext|> | 8 |
lolphp | midir | ckfliab | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>>but only sometimes
No. `0 == '0'` is always true. You've used `in_array` to confuse the matter but you're comparing something totally different:
var_dump(0 == 'foo'); // true (numeric comparison)
var_dump('0' == 'foo'); // false (string comparison)<|eor|><|eols|><|endoftext|> | 6 |
lolphp | catcradle5 | ckfw2xk | <|sols|><|sot|>I'm a PHP fan, but this still blows my mind. 0 == '0', but only sometimes.<|eot|><|sol|>http://3v4l.org/BRUBg<|eol|><|sor|>Just because 0 == '0' doesn't mean that '0' == X where 0 == X
http://3v4l.org/7gslD<|eor|><|sor|>Unlike regular equality, php equality isn't transitive. `true == "php" == 0 == false`
Sometimes I wonder why php even keeps `==` around.<|eor|><|sor|>Because it's a fast and easy way to compare straightforward data w/o the need of converting variables back and forth. No convert.ToDouble['variable'] or anything like that needed first (and then back to a string when you're done).
It saves steps, particularly when you have data that switches back and forth a lot or there's text that contains #s you want to use in PHP code.
<|eor|><|sor|>Yeah, and when you do
if (strcmp($password,$_POST["password"]) == 0)
you just have to pass `submit.php?password[]=a` which will make `$_POST["password"]` an ARRAY because of how convenient PHP is
then the strcmp will give you an error, but it will also be equal to zero AND IT WON'T STOP EXECUTING THE SCRIPT so it will let you into the site
you literally have to make a specific effort not to get fucked over<|eor|><|sor|>I remember encountering exactly this in a CTF I did a while back.
It baffles me that someone would actually recommend using PHP's (or Javascript's) loose equality operators for anything.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | Porges | 2dkfw4 | <|sols|><|sot|>All right, which one of you is this?<|eot|><|sol|>https://twitter.com/jakedonham/status/499983826638995458<|eol|><|eols|><|endoftext|> | 52 |
lolphp | fred_emmott | cjqgqkh | <|sols|><|sot|>All right, which one of you is this?<|eot|><|sol|>https://twitter.com/jakedonham/status/499983826638995458<|eol|><|sor|>Proof: http://cl.ly/image/0k2b0l1Y2c0Z<|eor|><|eols|><|endoftext|> | 66 |
lolphp | joepie91 | 1twal5 | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|eols|><|endoftext|> | 50 |
lolphp | duskwuff | cec5jfp | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>Working as (confusingly) designed.
`$obj->func` and `$obj->func()` do not reference the same thing. The first one is referring to an instance variable of `$obj`, and the second one is calling a method on the class of `$obj`. While some languages, like Python, unify the two, PHP does not.
The real unfortunate bit is that `($obj->func)()` doesn't parse (at least, not in PHP 5.4).<|eor|><|eols|><|endoftext|> | 33 |
lolphp | Lokaltog | cec2i1n | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>A fractal of bad design indeed.<|eor|><|eols|><|endoftext|> | 22 |
lolphp | user0x29a | cecfp9o | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>Working as (confusingly) designed.
`$obj->func` and `$obj->func()` do not reference the same thing. The first one is referring to an instance variable of `$obj`, and the second one is calling a method on the class of `$obj`. While some languages, like Python, unify the two, PHP does not.
The real unfortunate bit is that `($obj->func)()` doesn't parse (at least, not in PHP 5.4).<|eor|><|sor|>[deleted]<|eor|><|sor|>thats because php declares half of its bugs as the intended behabiour in the docs afterwards and half assed fixes the other half<|eor|><|eols|><|endoftext|> | 19 |
lolphp | joepie91 | cecgy4j | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>> $this->func contains a Closure (ie. anonymous function).
A closure is a function which keeps references to it's enclosing scope, the word you might be looking for is lambda.<|eor|><|soopr|>I'm not saying that the term "closure" is correct, but that's what PHP calls it - even the object class name is Closure. Don't ask me why.<|eoopr|><|eols|><|endoftext|> | 11 |
lolphp | boxingdog | cec7hi2 | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>$this->func() != $this->func<|eor|><|eols|><|endoftext|> | 10 |
lolphp | joepie91 | cec4wkw | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>So, you have to define it first... <|eor|><|soopr|>In both cases, $this->func refers to the same "closure". In the latter case, it is assigned to a local variable before calling it; in the former, it is called directly as a member variable.<|eoopr|><|eols|><|endoftext|> | 9 |
lolphp | himdel | ceclveu | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>Working as (confusingly) designed.
`$obj->func` and `$obj->func()` do not reference the same thing. The first one is referring to an instance variable of `$obj`, and the second one is calling a method on the class of `$obj`. While some languages, like Python, unify the two, PHP does not.
The real unfortunate bit is that `($obj->func)()` doesn't parse (at least, not in PHP 5.4).<|eor|><|sor|>Yep, same as in Javascript where `this` refers to different things depending on whether you've been called as `a.b()` or `var f = a.b; f()`.<|eor|><|sor|>Not really true. In JS you're calling the same function in each case, just with a different ``this``. In PHP, you're accessing a completely different bucket.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | joepie91 | cecgyz5 | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>Working as (confusingly) designed.
`$obj->func` and `$obj->func()` do not reference the same thing. The first one is referring to an instance variable of `$obj`, and the second one is calling a method on the class of `$obj`. While some languages, like Python, unify the two, PHP does not.
The real unfortunate bit is that `($obj->func)()` doesn't parse (at least, not in PHP 5.4).<|eor|><|soopr|>That makes me wonder why it was designed like this in the first place, and "because that's how it works internally" really isn't a valid reason. It should behave in a way that is logical (and consistent) to the third-party developer using it, not to the guy who implemented it.
If I wanted to use it "how it works internally", I'd be writing directly in C.<|eoopr|><|eols|><|endoftext|> | 7 |
lolphp | djsumdog | cedr9ye | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>reminds me...
$this->class_string::meth();
fails, instead must
$class = $this->class_string;
$class::meth();<|eor|><|sor|>Yep. You can't chain together function calls. It annoyed me years ago when I couldn't do $foo->bar()[0]. If bar returned an array and I wanted that first element, it had to be assigned to a variable first.
Back then I didn't realize this was due to a bigger problem with just the horrible innards of how the PHP parser works. <|eor|><|eols|><|endoftext|> | 6 |
lolphp | dagbrown | cecgt7h | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>$this->func() != $this->func<|eor|><|sor|> $this->func() != $this->func != $func=$this->func;$func();
My poor head.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | oridb | cemgro7 | <|sols|><|sot|>Really, PHP? Really?<|eot|><|sol|>http://sprunge.us/CaQX?php<|eol|><|sor|>Working as (confusingly) designed.
`$obj->func` and `$obj->func()` do not reference the same thing. The first one is referring to an instance variable of `$obj`, and the second one is calling a method on the class of `$obj`. While some languages, like Python, unify the two, PHP does not.
The real unfortunate bit is that `($obj->func)()` doesn't parse (at least, not in PHP 5.4).<|eor|><|soopr|>That makes me wonder why it was designed like this in the first place, and "because that's how it works internally" really isn't a valid reason. It should behave in a way that is logical (and consistent) to the third-party developer using it, not to the guy who implemented it.
If I wanted to use it "how it works internally", I'd be writing directly in C.<|eoopr|><|sor|>The reason it was designed that way was that closures were an afterthought. Allowing functions and variables to have independent namespaces within an object makes sense, *if* you don't allow functions as variables. Imagine, for example, a getter:
foo.bar() { return this.bar}
Other languages have the same distinction. Java, for example, has methods and instance variables in different namespaces:
class Foo {
int bar() { return 42; }
int bar;
}
Lisp is another language where a number of implementations made this decision. Common lisp is an example of such a Lisp-2 (that is, a lisp with 2 parallel namespaces: one for functions, one for variables).
The part that makes me go WTF is this:
$func = $this->func;
If you put variables in a separate namespace, put them in a separate namespace FFS.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | Serialk | 1rxey4 | <|soss|><|sot|>Some useful functions from the PHP standard library<|eot|><|sost|>* http://www.php.net/manual/en/function.jewishtojd.php
* http://www.php.net/manual/en/function.easter-date.php
* http://www.php.net/manual/en/function.easter-days.php
<|eost|><|eoss|><|endoftext|> | 49 |
lolphp | scshunt | cdrvtku | <|soss|><|sot|>Some useful functions from the PHP standard library<|eot|><|sost|>* http://www.php.net/manual/en/function.jewishtojd.php
* http://www.php.net/manual/en/function.easter-date.php
* http://www.php.net/manual/en/function.easter-days.php
<|eost|><|sor|>The easter functions assume that the vernal equinox is on March 21. This hasn't been true since 2007 and won't be true again for decades.<|eor|><|eoss|><|endoftext|> | 38 |
lolphp | phoshi | cds033t | <|soss|><|sot|>Some useful functions from the PHP standard library<|eot|><|sost|>* http://www.php.net/manual/en/function.jewishtojd.php
* http://www.php.net/manual/en/function.easter-date.php
* http://www.php.net/manual/en/function.easter-days.php
<|eost|><|sor|>As an aside, I just love the consistent naming...
* JDToJulian
* jdtounix
* cal_to_jd
...especially when you consider that function names are case-insensitive, so jdtounix _could_ in fact be changed to JDToUnix in the docs with nothing lost in terms of backwards compatibility.<|eor|><|sor|>PHP is *not* case insensitive, it is case insensitive with respect to the current locale. Which leads to bugs like [this](https://bugs.php.net/bug.php?id=18556), where changing the locale can break php.<|eor|><|eoss|><|endoftext|> | 30 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.