subreddit stringclasses 7
values | author stringlengths 3 20 | id stringlengths 5 7 | content stringlengths 67 30.4k | score int64 0 140k |
|---|---|---|---|---|
lolphp | crankybadger | d046o31 | <|sols|><|sot|>Oops, there's a typo in the Mersenne twister RNG code<|eot|><|sol|>http://git.php.net/?p=php-src.git;a=commitdiff;h=6f6bd8ce531636134efd5f669a4e8373fb2e9e51<|eol|><|sor|>https://www.xkcd.com/221/
As always, a relevant xkcd<|eor|><|sor|>Xkcd is humour for eunuchs<|eor|><|sor|>It's funnier than you are.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | midir | d04ycp7 | <|sols|><|sot|>Oops, there's a typo in the Mersenne twister RNG code<|eot|><|sol|>http://git.php.net/?p=php-src.git;a=commitdiff;h=6f6bd8ce531636134efd5f669a4e8373fb2e9e51<|eol|><|sor|>The fun never stops! https://www.reddit.com/r/lolphp/comments/46fxi8/typofixing_commit_in_mersenne_twister_rng_code_is_reverted/<|eor|><|eols|><|endoftext|> | 7 |
lolphp | the_alias_of_andrea | d04c79o | <|sols|><|sot|>Oops, there's a typo in the Mersenne twister RNG code<|eot|><|sol|>http://git.php.net/?p=php-src.git;a=commitdiff;h=6f6bd8ce531636134efd5f669a4e8373fb2e9e51<|eol|><|sor|>Huh, I would've thought that PHP would import the code wholesale. I wonder how this error could have been introduced.
Also, wow, that's probably a pretty bad backwards-compatibility break.<|eor|><|sor|>How exactly is it a BC break? Doesn't the function go from returning randomish data to returning randomish data?<|eor|><|sor|>Because you can seed the random number generator, and some applications require reproducibility of a pseudo-random sequence from a given seed.<|eor|><|sor|>...ah.
That's a tiny, *tiny* BC break in my book. On par with the free jolts of energy.<|eor|><|sor|>Tiny? It's pretty bad if you're, for example, running a simulation based on it. At least you can probably emulate the old behaviour in userland, though.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | Kronal | d04i614 | <|sols|><|sot|>Oops, there's a typo in the Mersenne twister RNG code<|eot|><|sol|>http://git.php.net/?p=php-src.git;a=commitdiff;h=6f6bd8ce531636134efd5f669a4e8373fb2e9e51<|eol|><|sor|>Huh, I would've thought that PHP would import the code wholesale. I wonder how this error could have been introduced.
Also, wow, that's probably a pretty bad backwards-compatibility break.<|eor|><|sor|>How exactly is it a BC break? Doesn't the function go from returning randomish data to returning randomish data?<|eor|><|sor|>Because you can seed the random number generator, and some applications require reproducibility of a pseudo-random sequence from a given seed.<|eor|><|sor|>Well that could be the case, but at least people learn next time they should implement even a simple LCG on their own if they want to have the same results.
See, PHP teaches you value life lessons :-)<|eor|><|sor|>Uh, PHP provides a way to specify a seed, so you should be able to rely on this behaviour.<|eor|><|sor|>When using the same language version, absolutely, but not necessarily to be reliable between different versions. A seed is only useful as long as the other characteristics and implementation are kept the same. For example, a 32bit MT and a 64bit MT would give you different results from the same seed, [but there are a bunch of other parameters](https://en.wikipedia.org/wiki/Mersenne_Twister#Algorithmic_detail).
And nothing in PHP guarantees you consistence between versions as far as I know.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | flying-sheep | d05viim | <|sols|><|sot|>Oops, there's a typo in the Mersenne twister RNG code<|eot|><|sol|>http://git.php.net/?p=php-src.git;a=commitdiff;h=6f6bd8ce531636134efd5f669a4e8373fb2e9e51<|eol|><|sor|>This is why we have unit tests, kids. <|eor|><|sor|>Except that [they didn't](http://git.php.net/?p=php-src.git;a=commitdiff;h=6f6bd8ce531636134efd5f669a4e8373fb2e9e51#patch2)<|eor|><|sor|>Well, we do now: https://github.com/php/php-src/commit/a50c31da1917bb07b3c11f229125ab8d1f0b9b70<|eor|><|sor|>dafuq, how is this desirable?<|eor|><|sor|>Er, because now we know if we break it?<|eor|><|sor|>no, i meant to make sure to have this behavior.
they removed a test that tested for correct behavior and added one that tested for wrong one.<|eor|><|sor|>> no, i meant to make sure to have this behavior.
Because existing applications might rely on it. And while we may correct our Mersenne Twister implementation in future, while it's broken we need to check we don't break it further.<|eor|><|sor|>thats OK if you have the correct fix in an inbound branch for the next release.
its not OK to say well, this is our life now, gotta live with it<|eor|><|eols|><|endoftext|> | 5 |
lolphp | poizan42 | 23oe47 | <|sols|><|sot|>This is not the array key you are looking for<|eot|><|sol|>http://codepad.org/0C0GivUF<|eol|><|eols|><|endoftext|> | 86 |
lolphp | HelloAnnyong | cgz91q7 | <|sols|><|sot|>This is not the array key you are looking for<|eot|><|sol|>http://codepad.org/0C0GivUF<|eol|><|soopr|>What is actually going on here ??!?!??!
http://codepad.org/FNeda0KY<|eoopr|><|sor|>> What is actually going on here ??!?!??!
PHP<|eor|><|sor|> array(1) {
["42"]=>
string(3) "wat"
}
This should not exist. [Look, it even says so in the documentation](http://php.net/manual/en/language.types.array.php)!
> A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08").
The string "42" should be cast to the integer 42 when the array is created. If you create an array the 'normal' way, that's [exactly what happens](http://codepad.org/SvJ0FqV8).
For some insane reason casting a stdclass to an array allows numeric strings to get into the set of keys, thereby unleashing Zalgo, the Nezperdian Hivemind of Chaos via inconsistency.
When you do a lookup like $x["42"], PHP says 'ooh, that's a numeric string, I should cast it before doing the lookup', casts it and finds nothing. $keys[0] also contains "42" and the same PHP-logic is applied.
[TL;DR](http://i0.kym-cdn.com/photos/images/newsfeed/000/086/344/carl1.jpg)
<|eor|><|sor|>> A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08").
This is actually false! The documentation lies. Numeric keys that fit inside an integer (or is it float?) on the current architecture will be cast to integers. But longer strings will not, [as I describe in a recent thread](http://www.reddit.com/r/lolphp/comments/239fmc/string_no_this_looks_like_a_number_it_must_be_one/cgyh3gy?context=3).
Not only that, but creating an array with integer literals behaves differently than creating one with string literals.
[Take a look at this.](http://codepad.org/mR1aErin)
$number_key_array = array(
12345 => "Foo",
123451234512345 => "Bar",
123451234512345123451234512345 => "Baz"
);
var_dump($number_key_array);
$string_key_array = array(
"12345" => "Foo",
"123451234512345" => "Bar",
"123451234512345123451234512345" => "Baz"
);
var_dump($string_key_array);
Results in this output:
array(2) {
[12345]=>
string(3) "Foo"
[-2147483648]=>
string(3) "Baz"
}
array(3) {
[12345]=>
string(3) "Foo"
["123451234512345"]=>
string(3) "Bar"
["123451234512345123451234512345"]=>
string(3) "Baz"
}
Two big "what the fuck"s there:
First that using any large integer literal as a key casts the key to `INT_MIN`.
Second that explicitly specifying string keys casts only some of them to integers.<|eor|><|eols|><|endoftext|> | 27 |
lolphp | HelloAnnyong | cgz43ob | <|sols|><|sot|>This is not the array key you are looking for<|eot|><|sol|>http://codepad.org/0C0GivUF<|eol|><|sor|>This is *amazing*.
I think this might actually be the best one on this subreddit. All the others can be explained in some way by understanding the underlying mechanics of type coercion, etc., etc.
But this one is pure WTF.<|eor|><|eols|><|endoftext|> | 25 |
lolphp | jmcs | cgz0107 | <|sols|><|sot|>This is not the array key you are looking for<|eot|><|sol|>http://codepad.org/0C0GivUF<|eol|><|soopr|>What is actually going on here ??!?!??!
http://codepad.org/FNeda0KY<|eoopr|><|sor|>> What is actually going on here ??!?!??!
PHP<|eor|><|eols|><|endoftext|> | 24 |
lolphp | poizan42 | cgyyr5m | <|sols|><|sot|>This is not the array key you are looking for<|eot|><|sol|>http://codepad.org/0C0GivUF<|eol|><|soopr|>What is actually going on here ??!?!??!
http://codepad.org/FNeda0KY<|eoopr|><|eols|><|endoftext|> | 19 |
lolphp | suspiciously_calm | cgz2i3n | <|sols|><|sot|>This is not the array key you are looking for<|eot|><|sol|>http://codepad.org/0C0GivUF<|eol|><|sor|>Now this is exactly the kind of assert I would put in a unit test for an array/map library.<|eor|><|eols|><|endoftext|> | 18 |
lolphp | TheGreatFohl | cgz317a | <|sols|><|sot|>This is not the array key you are looking for<|eot|><|sol|>http://codepad.org/0C0GivUF<|eol|><|sor|>Please tell me that this is a bug and not "intended by design"<|eor|><|eols|><|endoftext|> | 7 |
lolphp | steadweb | cgzrzc7 | <|sols|><|sot|>This is not the array key you are looking for<|eot|><|sol|>http://codepad.org/0C0GivUF<|eol|><|sor|>"I have no idea what I'm doing."
Stupid inconsistency. http://codepad.org/phKfL4qj.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | OneWingedShark | ch0g04e | <|sols|><|sot|>This is not the array key you are looking for<|eot|><|sol|>http://codepad.org/0C0GivUF<|eol|><|sor|>Now this is exactly the kind of assert I would put in a unit test for an array/map library.<|eor|><|sor|>The thing I take away from this is: ***don't write your libraries in PHP!***<|eor|><|eols|><|endoftext|> | 6 |
lolphp | InconsiderateBastard | cgzb49p | <|sols|><|sot|>This is not the array key you are looking for<|eot|><|sol|>http://codepad.org/0C0GivUF<|eol|><|soopr|>What is actually going on here ??!?!??!
http://codepad.org/FNeda0KY<|eoopr|><|sor|>It looks like when you cast the object to an array it just copies the public property names directly into an array, even though arrays can't have string representations of integers.
That becomes a problem because objects don't have integers as property names. Even if you set a property name to an integer, it'll end up being a string.
One can't have string representations of integers, one can't have integers unless they are string representations.
You can use get_object_vars instead of casting array to avoid this strange issue.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | barubary | d9kcm0 | <|soss|><|sot|>PHP is whitespace insensitive, except when it isn't (round 2)<|eot|><|sost|>As [the PHP manual explains](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) about double-quoted strings:
> If a dollar sign (`$`) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
Well.
<?php
$truE = 42;
echo "case 1: ${truE}", "\n";
echo "case 2: ${truE }", "\n";
echo "case 3: ${ truE}", "\n";
Output:
case 1: 42
Notice: Undefined variable: 1 in /in/IsMiR on line 5
case 2:
Notice: Undefined variable: 1 in /in/IsMiR on line 6
case 3:
([Live demo](https://3v4l.org/IsMiR))
Apparently if the thing inside `${...}` is not a plain identifier (e.g. if it contains spaces), it is evaluated as an expression and the result converted to a string, which is then looked up dynamically as the name of a variable. That's how `${truE }` first evaluates `truE` (interpreted as `true` because constants (unlike variable names) are case insensitive), converts it to the string `"1"`, then looks up `$1`.
This doesn't seem to be documented anywhere.
Of course,
echo "${ "truE" }", "\n";
works as expected (unless you didn't expect it to do that, in which case your expectations were wrong).<|eost|><|eoss|><|endoftext|> | 82 |
lolphp | fell_ratio | f1ienxo | <|soss|><|sot|>PHP is whitespace insensitive, except when it isn't (round 2)<|eot|><|sost|>As [the PHP manual explains](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) about double-quoted strings:
> If a dollar sign (`$`) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
Well.
<?php
$truE = 42;
echo "case 1: ${truE}", "\n";
echo "case 2: ${truE }", "\n";
echo "case 3: ${ truE}", "\n";
Output:
case 1: 42
Notice: Undefined variable: 1 in /in/IsMiR on line 5
case 2:
Notice: Undefined variable: 1 in /in/IsMiR on line 6
case 3:
([Live demo](https://3v4l.org/IsMiR))
Apparently if the thing inside `${...}` is not a plain identifier (e.g. if it contains spaces), it is evaluated as an expression and the result converted to a string, which is then looked up dynamically as the name of a variable. That's how `${truE }` first evaluates `truE` (interpreted as `true` because constants (unlike variable names) are case insensitive), converts it to the string `"1"`, then looks up `$1`.
This doesn't seem to be documented anywhere.
Of course,
echo "${ "truE" }", "\n";
works as expected (unless you didn't expect it to do that, in which case your expectations were wrong).<|eost|><|sor|>This is a quality WTF.<|eor|><|eoss|><|endoftext|> | 31 |
lolphp | tdammers | f1iknd9 | <|soss|><|sot|>PHP is whitespace insensitive, except when it isn't (round 2)<|eot|><|sost|>As [the PHP manual explains](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) about double-quoted strings:
> If a dollar sign (`$`) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
Well.
<?php
$truE = 42;
echo "case 1: ${truE}", "\n";
echo "case 2: ${truE }", "\n";
echo "case 3: ${ truE}", "\n";
Output:
case 1: 42
Notice: Undefined variable: 1 in /in/IsMiR on line 5
case 2:
Notice: Undefined variable: 1 in /in/IsMiR on line 6
case 3:
([Live demo](https://3v4l.org/IsMiR))
Apparently if the thing inside `${...}` is not a plain identifier (e.g. if it contains spaces), it is evaluated as an expression and the result converted to a string, which is then looked up dynamically as the name of a variable. That's how `${truE }` first evaluates `truE` (interpreted as `true` because constants (unlike variable names) are case insensitive), converts it to the string `"1"`, then looks up `$1`.
This doesn't seem to be documented anywhere.
Of course,
echo "${ "truE" }", "\n";
works as expected (unless you didn't expect it to do that, in which case your expectations were wrong).<|eost|><|sor|>Yes, the `"${x}"` syntax for variable interpolation should not exist and does not behave consistently with the rest of the language. The correct syntax is `"{$x}"`.<|eor|><|sor|>"Consistent with the rest of the language" implies that there is anything resembling consistency within the rest of the language...<|eor|><|eoss|><|endoftext|> | 30 |
lolphp | maweki | f1j4fcn | <|soss|><|sot|>PHP is whitespace insensitive, except when it isn't (round 2)<|eot|><|sost|>As [the PHP manual explains](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) about double-quoted strings:
> If a dollar sign (`$`) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
Well.
<?php
$truE = 42;
echo "case 1: ${truE}", "\n";
echo "case 2: ${truE }", "\n";
echo "case 3: ${ truE}", "\n";
Output:
case 1: 42
Notice: Undefined variable: 1 in /in/IsMiR on line 5
case 2:
Notice: Undefined variable: 1 in /in/IsMiR on line 6
case 3:
([Live demo](https://3v4l.org/IsMiR))
Apparently if the thing inside `${...}` is not a plain identifier (e.g. if it contains spaces), it is evaluated as an expression and the result converted to a string, which is then looked up dynamically as the name of a variable. That's how `${truE }` first evaluates `truE` (interpreted as `true` because constants (unlike variable names) are case insensitive), converts it to the string `"1"`, then looks up `$1`.
This doesn't seem to be documented anywhere.
Of course,
echo "${ "truE" }", "\n";
works as expected (unless you didn't expect it to do that, in which case your expectations were wrong).<|eost|><|sor|>wait, does this mean that ${ 1} refers to the same variable as ${ true} as ${ TRUE} as ${ 001} as ${ 1e0}?
edit: erm, yes ...
https://3v4l.org/nmuBJ<|eor|><|eoss|><|endoftext|> | 22 |
lolphp | nikic | f1iiyml | <|soss|><|sot|>PHP is whitespace insensitive, except when it isn't (round 2)<|eot|><|sost|>As [the PHP manual explains](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) about double-quoted strings:
> If a dollar sign (`$`) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
Well.
<?php
$truE = 42;
echo "case 1: ${truE}", "\n";
echo "case 2: ${truE }", "\n";
echo "case 3: ${ truE}", "\n";
Output:
case 1: 42
Notice: Undefined variable: 1 in /in/IsMiR on line 5
case 2:
Notice: Undefined variable: 1 in /in/IsMiR on line 6
case 3:
([Live demo](https://3v4l.org/IsMiR))
Apparently if the thing inside `${...}` is not a plain identifier (e.g. if it contains spaces), it is evaluated as an expression and the result converted to a string, which is then looked up dynamically as the name of a variable. That's how `${truE }` first evaluates `truE` (interpreted as `true` because constants (unlike variable names) are case insensitive), converts it to the string `"1"`, then looks up `$1`.
This doesn't seem to be documented anywhere.
Of course,
echo "${ "truE" }", "\n";
works as expected (unless you didn't expect it to do that, in which case your expectations were wrong).<|eost|><|sor|>Yes, the `"${x}"` syntax for variable interpolation should not exist and does not behave consistently with the rest of the language. The correct syntax is `"{$x}"`.<|eor|><|eoss|><|endoftext|> | 11 |
lolphp | barubary | f1jd5t3 | <|soss|><|sot|>PHP is whitespace insensitive, except when it isn't (round 2)<|eot|><|sost|>As [the PHP manual explains](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) about double-quoted strings:
> If a dollar sign (`$`) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
Well.
<?php
$truE = 42;
echo "case 1: ${truE}", "\n";
echo "case 2: ${truE }", "\n";
echo "case 3: ${ truE}", "\n";
Output:
case 1: 42
Notice: Undefined variable: 1 in /in/IsMiR on line 5
case 2:
Notice: Undefined variable: 1 in /in/IsMiR on line 6
case 3:
([Live demo](https://3v4l.org/IsMiR))
Apparently if the thing inside `${...}` is not a plain identifier (e.g. if it contains spaces), it is evaluated as an expression and the result converted to a string, which is then looked up dynamically as the name of a variable. That's how `${truE }` first evaluates `truE` (interpreted as `true` because constants (unlike variable names) are case insensitive), converts it to the string `"1"`, then looks up `$1`.
This doesn't seem to be documented anywhere.
Of course,
echo "${ "truE" }", "\n";
works as expected (unless you didn't expect it to do that, in which case your expectations were wrong).<|eost|><|sor|>In PHP, string variable interpolation syntax is `"{$foo}"`, not `"${foo}"`. Javascript has `\`${foo}\`\` which may be why you are confused.
EDIT: How does one mark up a leading backtick?<|eor|><|soopr|>I am not confused. PHP has two different interpolation syntaxes; please refer to the [PHP manual page](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) I linked to.
For simple variables, either `"{$foo}"` or `"${foo}"` will work.
IIRC Markdown requires a sequence of backticks as delimiter if you want to embed a single backtick as part of inline code:
`` `${foo}` ``
renders as `` `${foo}` ``.<|eoopr|><|eoss|><|endoftext|> | 11 |
lolphp | Altreus | f1k0gso | <|soss|><|sot|>PHP is whitespace insensitive, except when it isn't (round 2)<|eot|><|sost|>As [the PHP manual explains](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) about double-quoted strings:
> If a dollar sign (`$`) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
Well.
<?php
$truE = 42;
echo "case 1: ${truE}", "\n";
echo "case 2: ${truE }", "\n";
echo "case 3: ${ truE}", "\n";
Output:
case 1: 42
Notice: Undefined variable: 1 in /in/IsMiR on line 5
case 2:
Notice: Undefined variable: 1 in /in/IsMiR on line 6
case 3:
([Live demo](https://3v4l.org/IsMiR))
Apparently if the thing inside `${...}` is not a plain identifier (e.g. if it contains spaces), it is evaluated as an expression and the result converted to a string, which is then looked up dynamically as the name of a variable. That's how `${truE }` first evaluates `truE` (interpreted as `true` because constants (unlike variable names) are case insensitive), converts it to the string `"1"`, then looks up `$1`.
This doesn't seem to be documented anywhere.
Of course,
echo "${ "truE" }", "\n";
works as expected (unless you didn't expect it to do that, in which case your expectations were wrong).<|eost|><|sor|>In PHP, string variable interpolation syntax is `"{$foo}"`, not `"${foo}"`. Javascript has `\`${foo}\`\` which may be why you are confused.
EDIT: How does one mark up a leading backtick?<|eor|><|soopr|>I am not confused. PHP has two different interpolation syntaxes; please refer to the [PHP manual page](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) I linked to.
For simple variables, either `"{$foo}"` or `"${foo}"` will work.
IIRC Markdown requires a sequence of backticks as delimiter if you want to embed a single backtick as part of inline code:
`` `${foo}` ``
renders as `` `${foo}` ``.<|eoopr|><|sor|>Thank you, twice. I do not recall ever having encountered the \`${foo}\` syntax in the wild, or I overlooked it when I did.
In any case, it also is clear from that page why this is a PHPlol. So thank you thrice!<|eor|><|sor|>${foo} is probably stolen from Perl, which is a common theme of PHP: monkey see monkey do.
In Perl, this syntax works *everywhere* - it is the "lowest common denominator" for dereferencing, i.e. the base syntax that other methods are short for. In PHP, of course, monkey only saw.<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | SirClueless | f1kj8u0 | <|soss|><|sot|>PHP is whitespace insensitive, except when it isn't (round 2)<|eot|><|sost|>As [the PHP manual explains](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) about double-quoted strings:
> If a dollar sign (`$`) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
Well.
<?php
$truE = 42;
echo "case 1: ${truE}", "\n";
echo "case 2: ${truE }", "\n";
echo "case 3: ${ truE}", "\n";
Output:
case 1: 42
Notice: Undefined variable: 1 in /in/IsMiR on line 5
case 2:
Notice: Undefined variable: 1 in /in/IsMiR on line 6
case 3:
([Live demo](https://3v4l.org/IsMiR))
Apparently if the thing inside `${...}` is not a plain identifier (e.g. if it contains spaces), it is evaluated as an expression and the result converted to a string, which is then looked up dynamically as the name of a variable. That's how `${truE }` first evaluates `truE` (interpreted as `true` because constants (unlike variable names) are case insensitive), converts it to the string `"1"`, then looks up `$1`.
This doesn't seem to be documented anywhere.
Of course,
echo "${ "truE" }", "\n";
works as expected (unless you didn't expect it to do that, in which case your expectations were wrong).<|eost|><|sor|>wait, does this mean that ${ 1} refers to the same variable as ${ true} as ${ TRUE} as ${ 001} as ${ 1e0}?
edit: erm, yes ...
https://3v4l.org/nmuBJ<|eor|><|sor|>This makes sense to me. At least as much as anything in PHP makes sense. The point of `${}` outside of double-quoted strings is to lookup a variable named by an expression. So of course the interior of the braces is evaluated and a bunch of equivalent expressions might yield the same name. `${ 001}` and `${TRUE }` referring to the same variable is no more or less strange than `1+1` and `8/4` both evaluating to `2`.
The WTF of the original post to me is that a naked identifier is sometimes interpreted as a string literal when evaluated without whitespace around it and sometimes not, in the context of a double-quoted string. The fact that `"${truE}"` works at all and evaluates the same as `"${"truE"}"` is the real bizarre thing. Especially when `"{$truE}"` exists and does the same thing without any ambiguity in the same number of characters.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | dotancohen | f1jonpr | <|soss|><|sot|>PHP is whitespace insensitive, except when it isn't (round 2)<|eot|><|sost|>As [the PHP manual explains](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) about double-quoted strings:
> If a dollar sign (`$`) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
Well.
<?php
$truE = 42;
echo "case 1: ${truE}", "\n";
echo "case 2: ${truE }", "\n";
echo "case 3: ${ truE}", "\n";
Output:
case 1: 42
Notice: Undefined variable: 1 in /in/IsMiR on line 5
case 2:
Notice: Undefined variable: 1 in /in/IsMiR on line 6
case 3:
([Live demo](https://3v4l.org/IsMiR))
Apparently if the thing inside `${...}` is not a plain identifier (e.g. if it contains spaces), it is evaluated as an expression and the result converted to a string, which is then looked up dynamically as the name of a variable. That's how `${truE }` first evaluates `truE` (interpreted as `true` because constants (unlike variable names) are case insensitive), converts it to the string `"1"`, then looks up `$1`.
This doesn't seem to be documented anywhere.
Of course,
echo "${ "truE" }", "\n";
works as expected (unless you didn't expect it to do that, in which case your expectations were wrong).<|eost|><|sor|>In PHP, string variable interpolation syntax is `"{$foo}"`, not `"${foo}"`. Javascript has `\`${foo}\`\` which may be why you are confused.
EDIT: How does one mark up a leading backtick?<|eor|><|soopr|>I am not confused. PHP has two different interpolation syntaxes; please refer to the [PHP manual page](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) I linked to.
For simple variables, either `"{$foo}"` or `"${foo}"` will work.
IIRC Markdown requires a sequence of backticks as delimiter if you want to embed a single backtick as part of inline code:
`` `${foo}` ``
renders as `` `${foo}` ``.<|eoopr|><|sor|>Thank you, twice. I do not recall ever having encountered the \`${foo}\` syntax in the wild, or I overlooked it when I did.
In any case, it also is clear from that page why this is a PHPlol. So thank you thrice!<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | SirClueless | f1kqj0g | <|soss|><|sot|>PHP is whitespace insensitive, except when it isn't (round 2)<|eot|><|sost|>As [the PHP manual explains](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing) about double-quoted strings:
> If a dollar sign (`$`) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
Well.
<?php
$truE = 42;
echo "case 1: ${truE}", "\n";
echo "case 2: ${truE }", "\n";
echo "case 3: ${ truE}", "\n";
Output:
case 1: 42
Notice: Undefined variable: 1 in /in/IsMiR on line 5
case 2:
Notice: Undefined variable: 1 in /in/IsMiR on line 6
case 3:
([Live demo](https://3v4l.org/IsMiR))
Apparently if the thing inside `${...}` is not a plain identifier (e.g. if it contains spaces), it is evaluated as an expression and the result converted to a string, which is then looked up dynamically as the name of a variable. That's how `${truE }` first evaluates `truE` (interpreted as `true` because constants (unlike variable names) are case insensitive), converts it to the string `"1"`, then looks up `$1`.
This doesn't seem to be documented anywhere.
Of course,
echo "${ "truE" }", "\n";
works as expected (unless you didn't expect it to do that, in which case your expectations were wrong).<|eost|><|sor|>wait, does this mean that ${ 1} refers to the same variable as ${ true} as ${ TRUE} as ${ 001} as ${ 1e0}?
edit: erm, yes ...
https://3v4l.org/nmuBJ<|eor|><|sor|>This makes sense to me. At least as much as anything in PHP makes sense. The point of `${}` outside of double-quoted strings is to lookup a variable named by an expression. So of course the interior of the braces is evaluated and a bunch of equivalent expressions might yield the same name. `${ 001}` and `${TRUE }` referring to the same variable is no more or less strange than `1+1` and `8/4` both evaluating to `2`.
The WTF of the original post to me is that a naked identifier is sometimes interpreted as a string literal when evaluated without whitespace around it and sometimes not, in the context of a double-quoted string. The fact that `"${truE}"` works at all and evaluates the same as `"${"truE"}"` is the real bizarre thing. Especially when `"{$truE}"` exists and does the same thing without any ambiguity in the same number of characters.<|eor|><|sor|>PHP inteprets undefined constants as being equal to their names:
`echo A;` prints `A` and emits a warning: `Notice: Use of undefined constant A - assumed 'A'`.
This is on the surface level consistent with treating `${A}` and `${ A }` as `$A`.
So I thought that this is only a problem if the constant is defined, but nope:
<?php
define('A','B');
$A='a';
$B='b';
echo ${A};
echo ${ A};
echo "${A}";
echo "${ A}";
prints `bbab`.
So the name is only interpreted literally if it's inside an interpolated string and there are no spaces.<|eor|><|sor|>That was the WTF from the original post: inside double-quotes `"$"` is documented as gobbling up tokens greedily or using `{}` to specify a variable name. When in fact, when there is whitespace inside the `{}`, it does the same thing as outside double quotes and evaluates an expression.
Outside a double-quoted string, PHP is totally consistent. `${expr}` always does the same thing, which is evaluate `expr` as an expression and look up the result as a variable name. Inside a double-quoted string it does different things depending on whether `expr` contains whitespace or not. That's the WTF. `${2}` evaluating the same as `${1+1}` is totally normal. I've clarified the original comment.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | MMauro94 | 4zig9s | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|eols|><|endoftext|> | 81 |
lolphp | edave64 | d6w2mo5 | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|eols|><|endoftext|> | 51 |
lolphp | cythrawll | d6w8d9b | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|sor|>best way to do strict case switch, (warning ugly):
switch(true) {
case $test === 'a':
echo "this is strictly an a string";
break;
case $test === 0:
echo "this is stricly a 0 int";
break;
}
<|eor|><|eols|><|endoftext|> | 26 |
lolphp | Schmittfried | d6w9kj5 | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|sor|>Exactly. That's why I hate those half-ass "just use ===" excuses, it doesn't solve every problem related to this massively stupid type juggling. Had to write my own utility functions just to do *sane* weak comparisons (like "1" == 1 works, but "abc" == 0 results in an error).
Also: I hate dealing with legacy PHP. PHP 7 and its advantages are effective only if they are used consistently. You are fucked anyway when you have to call legacy functions (that you cannot change) that make heavy use of the == operator.
A few days ago I found myself writing this friendly comment after one hour of nasty debugging:
//You may wonder why this is not 0-based (or rather: why this has been changed from 0-based to 1-based).
//Jokes on you, it's obviously because PHP is a massive piece of shit. The level of crappiness is not
//even funny anymore. Never forget that <any non-numeric string> == 0 always evaluates to true.
//Especially keep this in mind whenever you want to use any of vBulletin's provided functions,
//because they are so fucking legacy that even the ancient greeks avoided them at all costs. Obviously
//vBulletin's code is full of usages of the == operator, so prepare to be fucked up by this bullshit
//whenever you pass anything falsy.
const MODE_IMPLICIT = 1;
const MODE_EXPLICIT = 2;
const MODE_BOTH = 3;<|eor|><|eols|><|endoftext|> | 23 |
lolphp | Schmittfried | d6w97py | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|sor|>best way to do strict case switch, (warning ugly):
switch(true) {
case $test === 'a':
echo "this is strictly an a string";
break;
case $test === 0:
echo "this is stricly a 0 int";
break;
}
<|eor|><|sor|>Huh, TIL. Every day you learn some new ways to deal with PHP's madness.<|eor|><|eols|><|endoftext|> | 17 |
lolphp | cfreak2399 | d6w1ur9 | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>Its a type conversion fail but I'm lost on this one. Unless everything passed to case gets converted to a string? But even then I thought PHP evaluated "0" as false?<|eor|><|eols|><|endoftext|> | 16 |
lolphp | Almamu | d6w2eh9 | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>Its a type conversion fail but I'm lost on this one. Unless everything passed to case gets converted to a string? But even then I thought PHP evaluated "0" as false?<|eor|><|sor|>Casting any string to int converts it to 0. $value is an int so the switch cases's are implicitely casted to int too.
```
echo (int) "one";
```<|eor|><|eols|><|endoftext|> | 16 |
lolphp | cythrawll | d6wd3pj | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|sor|>best way to do strict case switch, (warning ugly):
switch(true) {
case $test === 'a':
echo "this is strictly an a string";
break;
case $test === 0:
echo "this is stricly a 0 int";
break;
}
<|eor|><|sor|>Wouldn't the equivalent if-statements be nicer?
if($test === 'a') {
echo "this is strictly an a string";
} else if($test === 0) {
echo "this is strictly a 0 int";
}<|eor|><|sor|>Technically yes. But if your heart was set on switch statements because of fall through capabilities, etc... there's a way to do it.<|eor|><|eols|><|endoftext|> | 16 |
lolphp | madsohm | d6wcqoo | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|sor|>best way to do strict case switch, (warning ugly):
switch(true) {
case $test === 'a':
echo "this is strictly an a string";
break;
case $test === 0:
echo "this is stricly a 0 int";
break;
}
<|eor|><|sor|>Wouldn't the equivalent if-statements be nicer?
if($test === 'a') {
echo "this is strictly an a string";
} else if($test === 0) {
echo "this is strictly a 0 int";
}<|eor|><|eols|><|endoftext|> | 12 |
lolphp | cythrawll | d6w50hy | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>Its a type conversion fail but I'm lost on this one. Unless everything passed to case gets converted to a string? But even then I thought PHP evaluated "0" as false?<|eor|><|sor|>Casting any string to int converts it to 0. $value is an int so the switch cases's are implicitely casted to int too.
```
echo (int) "one";
```<|eor|><|sor|>not any string. Just non numerical ones. Even if they begin with numbers, it'll cast.
echo (int) "10"; // 10
echo (int) "10stuff blah whatever"; // 10
echo (int) "stuff10stuff"; // 0<|eor|><|eols|><|endoftext|> | 12 |
lolphp | mort96 | d6woqd7 | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|sor|>best way to do strict case switch, (warning ugly):
switch(true) {
case $test === 'a':
echo "this is strictly an a string";
break;
case $test === 0:
echo "this is stricly a 0 int";
break;
}
<|eor|><|sor|>That's clinically retarded. Your code would actually be readable if you just use if statements instead.<|eor|><|sor|>if statements and switches do different things. They don't have 1:1 overlapping functionality.<|eor|><|sor|>Prove it.<|eor|><|sor|> switch ($input) {
case "-h":
case "--help":
case "-help":
echo "Usage: whatever";
break;
case "-v":
case "--version":
case "-version":
echo "0.4.3";
break;
}
Is a kind of contrived example of how if and switch is different. You could solve it by using ||, but that would be quite a bit uglier.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | smog_alado | d6x5ryc | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|sor|>PHP isn't the only language with automatic type coercion and a `===` operator. I'm curious how other languages with similar features avoid this problem.<|eor|><|sor|>In Javascript, the switch statement is sane:
switch(42){
case "42":
console.log("insane");
break;
default:
console.log("sane");
break;
}
Hopefully someone else can add other languages to the comparison.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | Schmittfried | d6wr3vn | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|sor|>Exactly. That's why I hate those half-ass "just use ===" excuses, it doesn't solve every problem related to this massively stupid type juggling. Had to write my own utility functions just to do *sane* weak comparisons (like "1" == 1 works, but "abc" == 0 results in an error).
Also: I hate dealing with legacy PHP. PHP 7 and its advantages are effective only if they are used consistently. You are fucked anyway when you have to call legacy functions (that you cannot change) that make heavy use of the == operator.
A few days ago I found myself writing this friendly comment after one hour of nasty debugging:
//You may wonder why this is not 0-based (or rather: why this has been changed from 0-based to 1-based).
//Jokes on you, it's obviously because PHP is a massive piece of shit. The level of crappiness is not
//even funny anymore. Never forget that <any non-numeric string> == 0 always evaluates to true.
//Especially keep this in mind whenever you want to use any of vBulletin's provided functions,
//because they are so fucking legacy that even the ancient greeks avoided them at all costs. Obviously
//vBulletin's code is full of usages of the == operator, so prepare to be fucked up by this bullshit
//whenever you pass anything falsy.
const MODE_IMPLICIT = 1;
const MODE_EXPLICIT = 2;
const MODE_BOTH = 3;<|eor|><|sor|>I think honestly, it's my advice instead of working around the system. you learn to work with it. In most cases as long as you have a reference to the type juggling system. It should never take you by surprise. By implementing your own system, you're introducing your own type bugs and making the code more unreadable, and harder to predict behavior.
As far as working with legacy code, I feel ya there. I suggest always making sure types are correct before passing them off to legacy functions.
<|eor|><|sor|>There are no bugs. It isn't that hard to implement proper integer comparison. When I want strict equality I use === and when I want to allow *some* coercion, because I don't know the type for sure, I use my utility function. I will never use the == operator. Not because I don't know its semantics, but because its semantics suck.
>As far as working with legacy code, I feel ya there. I suggest always making sure types are correct before passing them off to legacy functions.
Easier said than done. In my case it was a wrongly executed if branch deep down the call tree, caused by said juggling.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | cythrawll | d6wg8om | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|sor|>best way to do strict case switch, (warning ugly):
switch(true) {
case $test === 'a':
echo "this is strictly an a string";
break;
case $test === 0:
echo "this is stricly a 0 int";
break;
}
<|eor|><|sor|>That's clinically retarded. Your code would actually be readable if you just use if statements instead.<|eor|><|sor|>if statements and switches do different things. They don't have 1:1 overlapping functionality.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | cythrawll | d6wf5s6 | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>This is the problem with the "just use ===" advice. There is no strict switch equivalent. There is no strict < or >. And forgetting the strict parameter on search functions is very easy.<|eor|><|sor|>The problem with that advice is that it is basically telling you a big fat lie, and that PHP's loose comparison system can be circumvented.
The purpose of the === advice is that you should know the types you are working with, and that should be your default. However, this is never an excuse to forget loose comparison, how it works in PHP and when and how it should be used.
I have the same sort of rules in JS. === is used 90% of the time, but every once in awhile you need to leverage that loose comparison.
So that "just use ===" isn't excuse to forget about how loose comparisons. It's an excuse to keep types in mind as you develop code.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | cfreak2399 | d6w7t0w | <|sols|><|sot|>PHP switches are the best<|eot|><|sol|>https://3v4l.org/6bJIX<|eol|><|sor|>Its a type conversion fail but I'm lost on this one. Unless everything passed to case gets converted to a string? But even then I thought PHP evaluated "0" as false?<|eor|><|sor|>Casting any string to int converts it to 0. $value is an int so the switch cases's are implicitely casted to int too.
```
echo (int) "one";
```<|eor|><|sor|>not any string. Just non numerical ones. Even if they begin with numbers, it'll cast.
echo (int) "10"; // 10
echo (int) "10stuff blah whatever"; // 10
echo (int) "stuff10stuff"; // 0<|eor|><|sor|>Looks like PHP needs to cast numbers written as words to convert properly to integers as well. Of course this would depend on your language settings ... /s
Edit: for those who are down-voting me: I'm being sarcastic.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | vytah | 23ze3g | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|eols|><|endoftext|> | 83 |
lolphp | jspenguin | ch2balr | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|sor|>Is there any sane reasoning behind this?<|eor|><|sor|>https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.c#L971
not really sane, but I found the code and the reason why. (kinda silly really)<|eor|><|sor|>That file contains over 10,000 gotos.<|eor|><|sor|>It looks like it's generated by YACC, so it doesn't count against them. <|eor|><|eols|><|endoftext|> | 26 |
lolphp | markrages | ch2pdr8 | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|sor|>Is there any sane reasoning behind this?<|eor|><|sor|>[Explained here](http://www.biblegateway.com/passage/?search=Matthew+20%3A16&version=KJV)<|eor|><|eols|><|endoftext|> | 25 |
lolphp | vytah | ch267al | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|sor|>This is dumb - aside from a Unix timestamp being converted to a normal Y-m-d styling or some other obscure/niche reason, why would you even think to put other characters inside of strtotime() and expect anything usable or consistent?
LOLPHP? More like RETARDEDCODER.<|eor|><|soopr|>`strtotime` supports various interesting relative date formats: https://php.net/manual/en/datetime.formats.relative.php
Things like "Monday next week", "yesterday noon", "first sat of July 2008" and so on.<|eoopr|><|eols|><|endoftext|> | 21 |
lolphp | cythrawll | ch290ls | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|sor|>Is there any sane reasoning behind this?<|eor|><|sor|>https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.c#L971
not really sane, but I found the code and the reason why. (kinda silly really)<|eor|><|eols|><|endoftext|> | 19 |
lolphp | dochoncho | chb7x3u | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|sor|>Why does this method take such input anyway? What's the use case? Its like COBOL for date math...
ADD TWO FORTNIGHTS TO THREE THURSDAYS FROM THE MONDAY BEFORE LAST<|eor|><|eols|><|endoftext|> | 17 |
lolphp | Thalagyrt | ch29ujr | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|sor|>Is there any sane reasoning behind this?<|eor|><|sor|>https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.c#L971
not really sane, but I found the code and the reason why. (kinda silly really)<|eor|><|sor|>That file contains over 10,000 gotos.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | Thalagyrt | ch2bcuj | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|sor|>Is there any sane reasoning behind this?<|eor|><|sor|>https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.c#L971
not really sane, but I found the code and the reason why. (kinda silly really)<|eor|><|sor|>That file contains over 10,000 gotos.<|eor|><|sor|>It looks like it's generated by YACC, so it doesn't count against them. <|eor|><|sor|>Yeah, that does seem to be the case. It's still pretty horrendous either way. There are some weird things in git blame though that make it look like the file's been edited by hand instead of always generated.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | scshunt | ch2eg1w | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|sor|>Is there any sane reasoning behind this?<|eor|><|sor|>https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.c#L971
not really sane, but I found the code and the reason why. (kinda silly really)<|eor|><|sor|>That file contains over 10,000 gotos.<|eor|><|sor|>It looks like it's generated by YACC, so it doesn't count against them. <|eor|><|sor|>It's in the source repository, so it does. Generated files in version control do not get excused.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | captainramen | ch2a9e3 | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|sor|>This is dumb - aside from a Unix timestamp being converted to a normal Y-m-d styling or some other obscure/niche reason, why would you even think to put other characters inside of strtotime() and expect anything usable or consistent?
LOLPHP? More like RETARDEDCODER.<|eor|><|soopr|>`strtotime` supports various interesting relative date formats: https://php.net/manual/en/datetime.formats.relative.php
Things like "Monday next week", "yesterday noon", "first sat of July 2008" and so on.<|eoopr|><|sor|>If it exists, eventually someone will use it. Hopefully no mission critical application relies on it.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | cparen | ch2nmd3 | <|sols|><|sot|>"last" means "last", "lAst" means "last", "Last" means "first"<|eot|><|sol|>http://codepad.viper-7.com/MclUwk<|eol|><|sor|>Is there any sane reasoning behind this?<|eor|><|sor|>https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.c#L971
not really sane, but I found the code and the reason why. (kinda silly really)<|eor|><|sor|>That file contains over 10,000 gotos.<|eor|><|sor|>It looks like it's generated by YACC, so it doesn't count against them. <|eor|><|sor|>Yeah, that does seem to be the case. It's still pretty horrendous either way. There are some weird things in git blame though that make it look like the file's been edited by hand instead of always generated.<|eor|><|sor|>That's the danger of checking in your Yacc output.
I know it's a trivial matter, but one of my favorite characteristics of parser combinators is the absence of generated code for people to mess with.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | __Tabs | 5q2at9 | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|eols|><|endoftext|> | 79 |
lolphp | Porges | dcwjiy2 | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|soopr|>What kind of sorcery is this? Do you have to put it in a variable to access them?<|eoopr|><|sor|>Nope, [it's even weirder than that](https://3v4l.org/HZU8R).<|eor|><|sor|>It adds properties to itself the first time you format it?
Lo, the *true* lolphp.<|eor|><|eols|><|endoftext|> | 46 |
lolphp | andsens | dcwdym8 | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|soopr|>What kind of sorcery is this? Do you have to put it in a variable to access them?<|eoopr|><|sor|>Nope, [it's even weirder than that](https://3v4l.org/HZU8R).<|eor|><|eols|><|endoftext|> | 37 |
lolphp | sfan5 | dcvr066 | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|eols|><|endoftext|> | 35 |
lolphp | jesseschalken | dcvrxcf | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|sor|>wait, [what the hell?](https://3v4l.org/uimNk)<|eor|><|eols|><|endoftext|> | 32 |
lolphp | __Tabs | dcvrkgf | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|soopr|>What kind of sorcery is this? Do you have to put it in a variable to access them?<|eoopr|><|eols|><|endoftext|> | 22 |
lolphp | eMZi0767 | dcvsgwv | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|sor|>wait, [what the hell?](https://3v4l.org/uimNk)<|eor|><|sor|>Consistency<|eor|><|eols|><|endoftext|> | 20 |
lolphp | jesseschalken | dcw6r5b | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|soopr|>What kind of sorcery is this? Do you have to put it in a variable to access them?<|eoopr|><|sor|>My guess would be yes, php's parser sucks. In other languages you can do stuff like `get_thing().method().attribute`, where PHP doesn't know what you're talking about. I don't know how much of that has been fixed in php 7.<|eor|><|sor|>`get_thing()->method()->attribute` has worked fine in PHP for as long as I can remember.
It's something specifically weird about this `DateTime` object.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | SnowdogU77 | dcwmlcz | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|soopr|>What kind of sorcery is this? Do you have to put it in a variable to access them?<|eoopr|><|sor|>Nope, [it's even weirder than that](https://3v4l.org/HZU8R).<|eor|><|sor|>It adds properties to itself the first time you format it?
Lo, the *true* lolphp.<|eor|><|sor|>On demand instance variable instantiation... For performance reasons, of course /s<|eor|><|eols|><|endoftext|> | 15 |
lolphp | BilgeXA | dcwnhb1 | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>Finally, a real fresh lolphp. This sub has been drying up.<|eor|><|eols|><|endoftext|> | 13 |
lolphp | emilvikstrom | dcwlbrj | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>If you take a look at __debuginfo() you will see that var_dump() prints all Public, Protected and Private properties (if not tasked to do otherwise).
The properties you try to access in your example are not intended to be accessed by the programmer directly, but rather with the ->format() method.
What you are witnessing here are just basic OOP principles at work
EDIT: sfan5's answer does confuse me tho... <|eor|><|sor|>But var_dump suffixes the name of private properties with `:private` so these properties are definitely public. They are not [documented](http://php.net/manual/en/class.datetime.php) though, so probably intended for internal use only.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | cjwelborn | dcvx1d5 | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|soopr|>What kind of sorcery is this? Do you have to put it in a variable to access them?<|eoopr|><|sor|>My guess would be yes, php's parser sucks. In other languages you can do stuff like `get_thing().method().attribute`, where PHP doesn't know what you're talking about. I don't know how much of that has been fixed in php 7.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | ezylot | dcw6vfu | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>If you take a look at __debuginfo() you will see that var_dump() prints all Public, Protected and Private properties (if not tasked to do otherwise).
The properties you try to access in your example are not intended to be accessed by the programmer directly, but rather with the ->format() method.
What you are witnessing here are just basic OOP principles at work
EDIT: sfan5's answer does confuse me tho... <|eor|><|eols|><|endoftext|> | 10 |
lolphp | lordmauve | dcxcdde | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|soopr|>What kind of sorcery is this? Do you have to put it in a variable to access them?<|eoopr|><|sor|>My guess would be yes, php's parser sucks. In other languages you can do stuff like `get_thing().method().attribute`, where PHP doesn't know what you're talking about. I don't know how much of that has been fixed in php 7.<|eor|><|sor|>`get_thing()->method()->attribute` has worked fine in PHP for as long as I can remember.
It's something specifically weird about this `DateTime` object.<|eor|><|sor|>Didn't work in PHP4. Some of us have long memories for that bullshit.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | ebvalaim | dcvzcwt | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>[they do](https://3v4l.org/jR47r)<|eor|><|soopr|>What kind of sorcery is this? Do you have to put it in a variable to access them?<|eoopr|><|sor|>My guess would be yes, php's parser sucks. In other languages you can do stuff like `get_thing().method().attribute`, where PHP doesn't know what you're talking about. I don't know how much of that has been fixed in php 7.<|eor|><|sor|>And that's the real WTF.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | sfan5 | dcwlg7g | <|sols|><|sot|>The DateTime object is dumped with 3 properties that don't even exist<|eot|><|sol|>https://3v4l.org/VhjMZ<|eol|><|sor|>If you take a look at __debuginfo() you will see that var_dump() prints all Public, Protected and Private properties (if not tasked to do otherwise).
The properties you try to access in your example are not intended to be accessed by the programmer directly, but rather with the ->format() method.
What you are witnessing here are just basic OOP principles at work
EDIT: sfan5's answer does confuse me tho... <|eor|><|sor|>> EDIT: sfan5's answer does confuse me tho...
It's PHP what did you expect<|eor|><|eols|><|endoftext|> | 6 |
lolphp | the_alias_of_andrea | 5bo7tx | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|eols|><|endoftext|> | 81 |
lolphp | OmnipotentEntity | d9qy5iw | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>For those asking "what's the alternative?":
Constants. You won't make any calculations with this value (it is not like 2 instances of protocol version 1.1 is protocol 2.2) and there is a finite number of options.
There might be people who want to do things like if($version > 1.1), but we all know, how good of an idea that would be (spoiler: not good at all).<|eor|><|sor|>Version numbers are strings, not numbers. 1.10 comes after 1.9<|eor|><|eols|><|endoftext|> | 28 |
lolphp | EmperorArthur | d9qc0zu | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>> protocol_version float
Maybe it does rounding. Try seeing if 1.1001 works.<|eor|><|eols|><|endoftext|> | 23 |
lolphp | merreborn | d9qellk | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>Is this an actual value you're reading or are you just making a crack at floating point numbers?<|eor|><|sor|>I think it's just a joke, although it turns out that specific number does have some meaning...
> > 1.1 is represented with the closest fraction with a power-of-two
> > denominator, 2476979795053773/2251799813685248. As is the case with all
> > Python floats, [this fraction has an exact decimal representation,
> > 1.100000000000000088817841970012523233890533447265625. ](https://mail.python.org/pipermail/python-list/2010-November/591118.html)
Floats are not intuitive...
Here's a relevant PHP example: https://3v4l.org/PFG0m
r/lolIEEE754<|eor|><|eols|><|endoftext|> | 23 |
lolphp | bestform | d9qu5i3 | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>For those asking "what's the alternative?":
Constants. You won't make any calculations with this value (it is not like 2 instances of protocol version 1.1 is protocol 2.2) and there is a finite number of options.
There might be people who want to do things like if($version > 1.1), but we all know, how good of an idea that would be (spoiler: not good at all).<|eor|><|eols|><|endoftext|> | 19 |
lolphp | the_alias_of_andrea | d9qgi38 | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>Is this an actual value you're reading or are you just making a crack at floating point numbers?<|eor|><|soopr|>> Is this an actual value you're reading
It's the 64-bit float representation of `1.1`, printed to full precision. (`php -dprecision=100 -r 'echo 0.1;'`)
I'm pretty sure PHP just tells the server `HTTP/1.1`, though. \^^<|eoopr|><|eols|><|endoftext|> | 16 |
lolphp | ElusiveGuy | d9r5t3a | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>For those asking "what's the alternative?":
Constants. You won't make any calculations with this value (it is not like 2 instances of protocol version 1.1 is protocol 2.2) and there is a finite number of options.
There might be people who want to do things like if($version > 1.1), but we all know, how good of an idea that would be (spoiler: not good at all).<|eor|><|sor|>Version numbers are strings, not numbers. 1.10 comes after 1.9<|eor|><|sor|>Version numbers are version numbers and ideally have their own type with however much precision (major? minor? build? revision? patch?) you need. Even treating them as strings is problematic, seeing as strings perform lexicographic comparison by default.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | kr094 | d9qdnmn | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>Is this an actual value you're reading or are you just making a crack at floating point numbers?<|eor|><|eols|><|endoftext|> | 12 |
lolphp | the_alias_of_andrea | d9qy9nm | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>For those asking "what's the alternative?":
Constants. You won't make any calculations with this value (it is not like 2 instances of protocol version 1.1 is protocol 2.2) and there is a finite number of options.
There might be people who want to do things like if($version > 1.1), but we all know, how good of an idea that would be (spoiler: not good at all).<|eor|><|soopr|>The typical solution would be two integers: the major version and the minor version.<|eoopr|><|eols|><|endoftext|> | 11 |
lolphp | the_alias_of_andrea | d9qya3i | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>For those asking "what's the alternative?":
Constants. You won't make any calculations with this value (it is not like 2 instances of protocol version 1.1 is protocol 2.2) and there is a finite number of options.
There might be people who want to do things like if($version > 1.1), but we all know, how good of an idea that would be (spoiler: not good at all).<|eor|><|sor|>In java there are big decimals (e.g. https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html), which serve this purpose.<|eor|><|soopr|>That falls apart when 1.10 comes after 1.9<|eoopr|><|eols|><|endoftext|> | 11 |
lolphp | josefx | d9r69wc | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>Is this an actual value you're reading or are you just making a crack at floating point numbers?<|eor|><|sor|>I think it's just a joke, although it turns out that specific number does have some meaning...
> > 1.1 is represented with the closest fraction with a power-of-two
> > denominator, 2476979795053773/2251799813685248. As is the case with all
> > Python floats, [this fraction has an exact decimal representation,
> > 1.100000000000000088817841970012523233890533447265625. ](https://mail.python.org/pipermail/python-list/2010-November/591118.html)
Floats are not intuitive...
Here's a relevant PHP example: https://3v4l.org/PFG0m
r/lolIEEE754<|eor|><|sor|>> Floats are not intuitive...
Floats are meh, just try to represent 1/3 as decimal. <|eor|><|eols|><|endoftext|> | 7 |
lolphp | NXTangl | dcds0c7 | <|sols|><|sot|>HTTP/1.100000000000000088817841970012523233890533447265625<|eot|><|sol|>http://php.net/manual/en/context.http.php#context.http.protocol-version<|eol|><|sor|>For those asking "what's the alternative?":
Constants. You won't make any calculations with this value (it is not like 2 instances of protocol version 1.1 is protocol 2.2) and there is a finite number of options.
There might be people who want to do things like if($version > 1.1), but we all know, how good of an idea that would be (spoiler: not good at all).<|eor|><|sor|>> You won't make any calculations with this value
I see you don't know any PHP "programmers".
They can and will use it for all sorts of stupid things.<|eor|><|sor|>Given how PHP handles number-y strings, they might very well do calculations on it *by accident.*<|eor|><|eols|><|endoftext|> | 6 |
lolphp | TortoiseWrath | 217e5t | <|sols|><|sot|>$functions["internal"][2019]: No, PHP! You were doing so well!<|eot|><|sol|>http://tortoisewrath.com/wat.htm<|eol|><|eols|><|endoftext|> | 82 |
lolphp | jb2386 | cgaha8v | <|sols|><|sot|>$functions["internal"][2019]: No, PHP! You were doing so well!<|eot|><|sol|>http://tortoisewrath.com/wat.htm<|eol|><|sor|>OH man, I hate it when I forget the order of the arguments for luvb(q/h& jy$e\^gl()
I mean, is it:
luvb(q/h& jy$e^gl($haystack, $needle, $forceExpectedBehaviour=false)
OR
luvb(q/h& jy$e^gl($needle, $garbagedump, $TryToBeUTF8Compatible=false) <|eor|><|eols|><|endoftext|> | 43 |
lolphp | ealf | cgafqc6 | <|sols|><|sot|>$functions["internal"][2019]: No, PHP! You were doing so well!<|eot|><|sol|>http://tortoisewrath.com/wat.htm<|eol|><|sor|>What exactly is going on here? is this due to the way PHP stores function names?<|eor|><|sor|>I think we know enough about how these people think to reconstruct what happened. Facts:
- the length distribution is the same for the garbage and the real names
- parsing all the source code every time you run it is... not the super fastest way to run code... so there are byte code caching tools that save the byte code after the parsing step
I'm going to guess...
- some of those byte code tools save byte code to disk
- someone looked at the byte code on disk and saw that it was unreadable (by them)
- they had a Brilliant Idea and hacked the byte code caching tool into two pieces, sold the first half as the PHP Source Encryptor and the second half as the Secure Runtime
- they got a bug report that you could see function names in the Encrypted Byte Code.
- since it's PHP, they solved it the First Way That Compiled, by "encrypting" the function names and placing a second copy of each function in the global function table
EDIT: oh Jesus wept it's not third party craziness, it's an official Zend thing. http://www.reddit.com/r/lolphp/comments/217e5t/functionsinternal2019_no_php_you_were_doing_so/cgalq50<|eor|><|eols|><|endoftext|> | 36 |
lolphp | Varriount | cgadi66 | <|sols|><|sot|>$functions["internal"][2019]: No, PHP! You were doing so well!<|eot|><|sol|>http://tortoisewrath.com/wat.htm<|eol|><|sor|>What exactly is going on here? is this due to the way PHP stores function names?<|eor|><|eols|><|endoftext|> | 21 |
lolphp | pdewacht | cgamglp | <|sols|><|sot|>$functions["internal"][2019]: No, PHP! You were doing so well!<|eot|><|sol|>http://tortoisewrath.com/wat.htm<|eol|><|sor|>What exactly is going on here? is this due to the way PHP stores function names?<|eor|><|sor|>I think we know enough about how these people think to reconstruct what happened. Facts:
- the length distribution is the same for the garbage and the real names
- parsing all the source code every time you run it is... not the super fastest way to run code... so there are byte code caching tools that save the byte code after the parsing step
I'm going to guess...
- some of those byte code tools save byte code to disk
- someone looked at the byte code on disk and saw that it was unreadable (by them)
- they had a Brilliant Idea and hacked the byte code caching tool into two pieces, sold the first half as the PHP Source Encryptor and the second half as the Secure Runtime
- they got a bug report that you could see function names in the Encrypted Byte Code.
- since it's PHP, they solved it the First Way That Compiled, by "encrypting" the function names and placing a second copy of each function in the global function table
EDIT: oh Jesus wept it's not third party craziness, it's an official Zend thing. http://www.reddit.com/r/lolphp/comments/217e5t/functionsinternal2019_no_php_you_were_doing_so/cgalq50<|eor|><|sor|>Additional data point: 2018 real names, 2018 garbage names.<|eor|><|eols|><|endoftext|> | 21 |
lolphp | duskwuff | cgalq50 | <|sols|><|sot|>$functions["internal"][2019]: No, PHP! You were doing so well!<|eot|><|sol|>http://tortoisewrath.com/wat.htm<|eol|><|sor|>The ridiculous-looking function names are related to Zend Optimizer (a loader for encrypted PHP files). They aren't present in stock PHP.<|eor|><|eols|><|endoftext|> | 20 |
lolphp | ajmarks | cgaho61 | <|sols|><|sot|>$functions["internal"][2019]: No, PHP! You were doing so well!<|eot|><|sol|>http://tortoisewrath.com/wat.htm<|eol|><|sor|>OH man, I hate it when I forget the order of the arguments for luvb(q/h& jy$e\^gl()
I mean, is it:
luvb(q/h& jy$e^gl($haystack, $needle, $forceExpectedBehaviour=false)
OR
luvb(q/h& jy$e^gl($needle, $garbagedump, $TryToBeUTF8Compatible=false) <|eor|><|sor|>Dude everybody knows named arguments are never going to work. Just ask Rasmusberry.<|eor|><|eols|><|endoftext|> | 17 |
lolphp | Fiech | cgb1x2i | <|sols|><|sot|>$functions["internal"][2019]: No, PHP! You were doing so well!<|eot|><|sol|>http://tortoisewrath.com/wat.htm<|eol|><|sor|>My favorites:
* 2723: `*`
* 3361: `no`
* 3583: `^z`
* 3334: Somehow turned into HTML...
<|eor|><|sor|>2396: guh?
<|eor|><|eols|><|endoftext|> | 8 |
lolphp | Various_Pickles | cgatqag | <|sols|><|sot|>$functions["internal"][2019]: No, PHP! You were doing so well!<|eot|><|sol|>http://tortoisewrath.com/wat.htm<|eol|><|sor|>I bet the last private key you passed to those OpenSSL functions is somewhere in there.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | kangaroowarcry | cgais1a | <|sols|><|sot|>$functions["internal"][2019]: No, PHP! You were doing so well!<|eot|><|sol|>http://tortoisewrath.com/wat.htm<|eol|><|sor|>2642? {[?<|eor|><|sor|>2396 guh?<|eor|><|eols|><|endoftext|> | 7 |
lolphp | Sarcastinator | 1zmsyo | <|soss|><|sot|>PHP Dereferencing<|eot|><|sost|>In PHP 5.4 this would break:
echo array(1, 2, 3)[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
Luckily, they added "dereferencing" in PHP 5.5 which would solve it! Hurray! And sure enough, it works!
However, the fix isn't very clever, because this will break in 5.5:
echo (array(1, 2, 3))[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
That's a little embarrassing.<|eost|><|eoss|><|endoftext|> | 78 |
lolphp | aftli | cfv541e | <|soss|><|sot|>PHP Dereferencing<|eot|><|sost|>In PHP 5.4 this would break:
echo array(1, 2, 3)[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
Luckily, they added "dereferencing" in PHP 5.5 which would solve it! Hurray! And sure enough, it works!
However, the fix isn't very clever, because this will break in 5.5:
echo (array(1, 2, 3))[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
That's a little embarrassing.<|eost|><|sor|>It's like they fixed a symptom instead of fixing the actual problem.<|eor|><|eoss|><|endoftext|> | 48 |
lolphp | EvilTerran | cfv6bpp | <|soss|><|sot|>PHP Dereferencing<|eot|><|sost|>In PHP 5.4 this would break:
echo array(1, 2, 3)[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
Luckily, they added "dereferencing" in PHP 5.5 which would solve it! Hurray! And sure enough, it works!
However, the fix isn't very clever, because this will break in 5.5:
echo (array(1, 2, 3))[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
That's a little embarrassing.<|eost|><|sor|>Judging by its behaviour, there seems to be a pattern in the design of the php "parser" of not re-using syntax where similar functionality is needed.
In this case, it seems to me that they used to parse array indexing with a rule like "$<variable>[<expression>]", and they just added another case "<function>(<arguments>)[<expression>]" alongside it.
Doing It Right would've been staying at a single rule, just making it "<expression>[<expression>]". But when does PHP ever do the right thing?
See also -- the addition of "foreach (... as list(...))" in 5.5, among others.<|eor|><|eoss|><|endoftext|> | 35 |
lolphp | EvilTerran | cfvqavm | <|soss|><|sot|>PHP Dereferencing<|eot|><|sost|>In PHP 5.4 this would break:
echo array(1, 2, 3)[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
Luckily, they added "dereferencing" in PHP 5.5 which would solve it! Hurray! And sure enough, it works!
However, the fix isn't very clever, because this will break in 5.5:
echo (array(1, 2, 3))[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
That's a little embarrassing.<|eost|><|sor|>Judging by its behaviour, there seems to be a pattern in the design of the php "parser" of not re-using syntax where similar functionality is needed.
In this case, it seems to me that they used to parse array indexing with a rule like "$<variable>[<expression>]", and they just added another case "<function>(<arguments>)[<expression>]" alongside it.
Doing It Right would've been staying at a single rule, just making it "<expression>[<expression>]". But when does PHP ever do the right thing?
See also -- the addition of "foreach (... as list(...))" in 5.5, among others.<|eor|><|sor|>If you really want to know - it all comes down to the $$a[$b] syntax, which is interpreted as ${$a[$b]} rather than ${$a}[$b]. Due to this unfortunate choice of precedence it's not possible to just nicely parse variables in a generic way. Everything needs to be special cased.
It would be nice to change the behavior of that (really totally useless) syntax and based on that, both massively simplify and fully generalize the variable syntax in PHP 6.<|eor|><|sor|>> the $$a[$b] syntax, which is interpreted as ${$a[$b]} rather than ${$a}[$b]
... you're shitting me.
> $ php -d error_reporting=E_ALL -r '$a = Array("foo" => "bar"); var_dump($$a["foo"]);'
>
> Notice: Undefined variable: bar in Command line code on line 1
> NULL
Jesus fucking christ, that's pants-on-head stupid.
And then, in the name of maintaining that terrible syntax choice, for a feature (variable-variables) you shouldn't even ever *use*, they fuck up the rest of the syntax too?
Wow.<|eor|><|eoss|><|endoftext|> | 19 |
lolphp | nikic | cfvg3nk | <|soss|><|sot|>PHP Dereferencing<|eot|><|sost|>In PHP 5.4 this would break:
echo array(1, 2, 3)[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
Luckily, they added "dereferencing" in PHP 5.5 which would solve it! Hurray! And sure enough, it works!
However, the fix isn't very clever, because this will break in 5.5:
echo (array(1, 2, 3))[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
That's a little embarrassing.<|eost|><|sor|>Judging by its behaviour, there seems to be a pattern in the design of the php "parser" of not re-using syntax where similar functionality is needed.
In this case, it seems to me that they used to parse array indexing with a rule like "$<variable>[<expression>]", and they just added another case "<function>(<arguments>)[<expression>]" alongside it.
Doing It Right would've been staying at a single rule, just making it "<expression>[<expression>]". But when does PHP ever do the right thing?
See also -- the addition of "foreach (... as list(...))" in 5.5, among others.<|eor|><|sor|>If you really want to know - it all comes down to the $$a[$b] syntax, which is interpreted as ${$a[$b]} rather than ${$a}[$b]. Due to this unfortunate choice of precedence it's not possible to just nicely parse variables in a generic way. Everything needs to be special cased.
It would be nice to change the behavior of that (really totally useless) syntax and based on that, both massively simplify and fully generalize the variable syntax in PHP 6.<|eor|><|eoss|><|endoftext|> | 18 |
lolphp | poizan42 | cfv7hjk | <|soss|><|sot|>PHP Dereferencing<|eot|><|sost|>In PHP 5.4 this would break:
echo array(1, 2, 3)[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
Luckily, they added "dereferencing" in PHP 5.5 which would solve it! Hurray! And sure enough, it works!
However, the fix isn't very clever, because this will break in 5.5:
echo (array(1, 2, 3))[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
That's a little embarrassing.<|eost|><|sor|>Judging by its behaviour, there seems to be a pattern in the design of the php "parser" of not re-using syntax where similar functionality is needed.
In this case, it seems to me that they used to parse array indexing with a rule like "$<variable>[<expression>]", and they just added another case "<function>(<arguments>)[<expression>]" alongside it.
Doing It Right would've been staying at a single rule, just making it "<expression>[<expression>]". But when does PHP ever do the right thing?
See also -- the addition of "foreach (... as list(...))" in 5.5, among others.<|eor|><|sor|>From what I understand the lexing, parsing and bytecode emitting in php is an intertwined mess.<|eor|><|eoss|><|endoftext|> | 17 |
lolphp | lisp-case | cfvhqtg | <|soss|><|sot|>PHP Dereferencing<|eot|><|sost|>In PHP 5.4 this would break:
echo array(1, 2, 3)[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
Luckily, they added "dereferencing" in PHP 5.5 which would solve it! Hurray! And sure enough, it works!
However, the fix isn't very clever, because this will break in 5.5:
echo (array(1, 2, 3))[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
That's a little embarrassing.<|eost|><|sor|>I'm not sure why you'd expect that to work, exactly.<|eor|><|sor|>Because there's no reason for it not to?
I just checked. The trivial translation works as expected in Python, Perl, Ruby, OCaml, and Javascript; that's all the non-PHP languages with dedicated indexing syntax and array literals I have ready access to. These languages all make it work by doing *nothing in particular*; the array literal is an expression, and since expressions might result in things that can be indexed a sane grammar will accommodate that. Sure some particular example might be nonsense semantically, but the parser shouldn't care about that.<|eor|><|eoss|><|endoftext|> | 15 |
lolphp | Sarcastinator | cfvk2dv | <|soss|><|sot|>PHP Dereferencing<|eot|><|sost|>In PHP 5.4 this would break:
echo array(1, 2, 3)[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
Luckily, they added "dereferencing" in PHP 5.5 which would solve it! Hurray! And sure enough, it works!
However, the fix isn't very clever, because this will break in 5.5:
echo (array(1, 2, 3))[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
That's a little embarrassing.<|eost|><|sor|>I'm not sure why you'd expect that to work, exactly.<|eor|><|sor|>Because there's no reason for it not to?
I just checked. The trivial translation works as expected in Python, Perl, Ruby, OCaml, and Javascript; that's all the non-PHP languages with dedicated indexing syntax and array literals I have ready access to. These languages all make it work by doing *nothing in particular*; the array literal is an expression, and since expressions might result in things that can be indexed a sane grammar will accommodate that. Sure some particular example might be nonsense semantically, but the parser shouldn't care about that.<|eor|><|sor|>Can you do it in asm? Haskell, C, C#, F#? I don't know why because it would work in some other language you'd expect it to in another.
EDIT: the downvotes are hilarious, lolphp truly is full of amateurs. <|eor|><|soopr|>It does work actually. The exception is ASM but that is because the syntax is completely different.<|eoopr|><|eoss|><|endoftext|> | 12 |
lolphp | nikic | cfvryss | <|soss|><|sot|>PHP Dereferencing<|eot|><|sost|>In PHP 5.4 this would break:
echo array(1, 2, 3)[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
Luckily, they added "dereferencing" in PHP 5.5 which would solve it! Hurray! And sure enough, it works!
However, the fix isn't very clever, because this will break in 5.5:
echo (array(1, 2, 3))[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
That's a little embarrassing.<|eost|><|sor|>Judging by its behaviour, there seems to be a pattern in the design of the php "parser" of not re-using syntax where similar functionality is needed.
In this case, it seems to me that they used to parse array indexing with a rule like "$<variable>[<expression>]", and they just added another case "<function>(<arguments>)[<expression>]" alongside it.
Doing It Right would've been staying at a single rule, just making it "<expression>[<expression>]". But when does PHP ever do the right thing?
See also -- the addition of "foreach (... as list(...))" in 5.5, among others.<|eor|><|sor|>If you really want to know - it all comes down to the $$a[$b] syntax, which is interpreted as ${$a[$b]} rather than ${$a}[$b]. Due to this unfortunate choice of precedence it's not possible to just nicely parse variables in a generic way. Everything needs to be special cased.
It would be nice to change the behavior of that (really totally useless) syntax and based on that, both massively simplify and fully generalize the variable syntax in PHP 6.<|eor|><|sor|>> the $$a[$b] syntax, which is interpreted as ${$a[$b]} rather than ${$a}[$b]
... you're shitting me.
> $ php -d error_reporting=E_ALL -r '$a = Array("foo" => "bar"); var_dump($$a["foo"]);'
>
> Notice: Undefined variable: bar in Command line code on line 1
> NULL
Jesus fucking christ, that's pants-on-head stupid.
And then, in the name of maintaining that terrible syntax choice, for a feature (variable-variables) you shouldn't even ever *use*, they fuck up the rest of the syntax too?
Wow.<|eor|><|sor|>Congrats, you finally understood PHP. It's all about backwards compatibility ;)
PS: It's really not just $$a[$b], but a number of these variable syntaxes implemented in the same way. E.g. the same issue also exists with $obj->$arr[$key](), which calls the method named $arr[$key], rather than the functor stored in $obj->$arr[$key]. It's these small things that are very rarely used that prevent a consistent/general variable syntax.<|eor|><|eoss|><|endoftext|> | 11 |
lolphp | ajmarks | cfv15dt | <|soss|><|sot|>PHP Dereferencing<|eot|><|sost|>In PHP 5.4 this would break:
echo array(1, 2, 3)[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
Luckily, they added "dereferencing" in PHP 5.5 which would solve it! Hurray! And sure enough, it works!
However, the fix isn't very clever, because this will break in 5.5:
echo (array(1, 2, 3))[0]
With the message
Parse error: syntax error, unexpected '[', expecting ',' or ';' in [...][...] on line 1
That's a little embarrassing.<|eost|><|sor|>/facepalm<|eor|><|eoss|><|endoftext|> | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.