subreddit
stringclasses
7 values
author
stringlengths
3
20
id
stringlengths
5
7
content
stringlengths
67
30.4k
score
int64
0
140k
lolphp
sumdog
c4x7wke
<|sols|><|sot|>10 reasons to use PHP<|eot|><|sol|>http://www.eschrade.com/page/10-reasons-to-use-php-for-your-mobile-project/<|eol|><|sor|>>The PHP Community I don't want to start about the PHP community, but don't underestimate the community. For many this is a huge point. When I started with chicken the extremely helpful irc channel was a way more important then a few precedents of performance. <|eor|><|sor|>Yea, the prostitute community can really help you out too. They're a great community of support once you get herpes. <|eor|><|eols|><|endoftext|>
7
lolphp
Altreus
qn784
<|soss|><|sot|>Computing an expression? But it's static :(<|eot|><|sost|>Despite being theoretically a programming language, PHP will not allow you to use an expression when constructing a static member variable. class Bla { private static $_thing = array( 'path' => BASE_PATH . '/relative/path' ); } This dies with "syntax error, unexpected '.', expected ')'". Apparently, actually computing the value of expressions is too much for this language. I am starting to suspect they're doing it intentionally so that their new releases have cool new features to advertise.<|eost|><|eoss|><|endoftext|>
25
lolphp
vytah
c3yxpsw
<|soss|><|sot|>Computing an expression? But it's static :(<|eot|><|sost|>Despite being theoretically a programming language, PHP will not allow you to use an expression when constructing a static member variable. class Bla { private static $_thing = array( 'path' => BASE_PATH . '/relative/path' ); } This dies with "syntax error, unexpected '.', expected ')'". Apparently, actually computing the value of expressions is too much for this language. I am starting to suspect they're doing it intentionally so that their new releases have cool new features to advertise.<|eost|><|sor|>Not very surprising. Not all expressions are pure, so the initialization of a static member using expressions is unsafe. Since PHP is dynamic (to idiotic extremes), purity tracking through a type system would catch the error too late to be useful. What would be useful is having an initialization function for static members, so any unsafety can be dealt with.<|eor|><|sor|>Java allows declaring static values with inpure expressions. It runs then in order of their declaration, when the class is first loaded. There is nothing to stop PHP doing the same; the fact it is dynamic is irrelevant. However in Java, if I use a class from two places, it is only loaded once. If I want it loaded more then once, I have to manually do that myself (i.e. through class loaders). In PHP it is normal to load a class multiple times, so should the static values be initialized each time, or just the once? This could lead to strange behaviour if it were re-initialized each time. This might be some of the logic behind why they are not supported.<|eor|><|sor|>But dying with a syntax error is not a reasonable thing to do. It could end with "ERROR: non-constant expression used for static member initialization", or something like that.<|eor|><|eoss|><|endoftext|>
8
lolphp
farsightxr20
c3z749w
<|soss|><|sot|>Computing an expression? But it's static :(<|eot|><|sost|>Despite being theoretically a programming language, PHP will not allow you to use an expression when constructing a static member variable. class Bla { private static $_thing = array( 'path' => BASE_PATH . '/relative/path' ); } This dies with "syntax error, unexpected '.', expected ')'". Apparently, actually computing the value of expressions is too much for this language. I am starting to suspect they're doing it intentionally so that their new releases have cool new features to advertise.<|eost|><|sor|>How about: define('FOO_PATH', BASE_PATH . '/relative/path'); class Bla { private static $_thing = array( 'path' => FOO_PATH ); } <|eor|><|sor|>[deleted]<|eor|><|sor|>And it avoids the real question: why would their static/member assignment grammar be different from their regular assignment grammar? And this begs a further question: if they allow arrays in their static assignment grammar, why wouldn't they just re-use the existing array grammar (which DOES allow use of expressions). They basically wrote _more_ code to give _less_ functionality for _no reason_.<|eor|><|eoss|><|endoftext|>
8
lolphp
nsfwIvan
c3z70hn
<|soss|><|sot|>Computing an expression? But it's static :(<|eot|><|sost|>Despite being theoretically a programming language, PHP will not allow you to use an expression when constructing a static member variable. class Bla { private static $_thing = array( 'path' => BASE_PATH . '/relative/path' ); } This dies with "syntax error, unexpected '.', expected ')'". Apparently, actually computing the value of expressions is too much for this language. I am starting to suspect they're doing it intentionally so that their new releases have cool new features to advertise.<|eost|><|sor|>PHP is Katamari Damacy rolling through the programming landscape, gathering whatever shiny it finds.<|eor|><|sor|>> PHP is Katamari Damacy rolling through the programming landscape, gathering whatever shity it finds.<|eor|><|eoss|><|endoftext|>
7
lolphp
vytah
c3yyeux
<|soss|><|sot|>Computing an expression? But it's static :(<|eot|><|sost|>Despite being theoretically a programming language, PHP will not allow you to use an expression when constructing a static member variable. class Bla { private static $_thing = array( 'path' => BASE_PATH . '/relative/path' ); } This dies with "syntax error, unexpected '.', expected ')'". Apparently, actually computing the value of expressions is too much for this language. I am starting to suspect they're doing it intentionally so that their new releases have cool new features to advertise.<|eost|><|sor|>Not very surprising. Not all expressions are pure, so the initialization of a static member using expressions is unsafe. Since PHP is dynamic (to idiotic extremes), purity tracking through a type system would catch the error too late to be useful. What would be useful is having an initialization function for static members, so any unsafety can be dealt with.<|eor|><|sor|>Java allows declaring static values with inpure expressions. It runs then in order of their declaration, when the class is first loaded. There is nothing to stop PHP doing the same; the fact it is dynamic is irrelevant. However in Java, if I use a class from two places, it is only loaded once. If I want it loaded more then once, I have to manually do that myself (i.e. through class loaders). In PHP it is normal to load a class multiple times, so should the static values be initialized each time, or just the once? This could lead to strange behaviour if it were re-initialized each time. This might be some of the logic behind why they are not supported.<|eor|><|sor|>But dying with a syntax error is not a reasonable thing to do. It could end with "ERROR: non-constant expression used for static member initialization", or something like that.<|eor|><|sor|>I 100% agree! This is actually a particular gripe of mine, as lots of invalid syntax can often be parsed, and then given a proper syntax error. For example: 'funciton foo( 1+2 )' could be correctly parsed, and then give a "expression '1+2'" is not allowed here, rather then a more generic syntax error. I also hate languages that show symbol names in error messages; i.e. 'expecting: T_SYNTAX_PARENTHESIS_LEFT_TERMINAL' instead of "expecting a '('", which is far more meaningful.<|eor|><|sor|>I hope you know how PHP calls a double colon...<|eor|><|eoss|><|endoftext|>
7
lolphp
Rhomboid
c3yw5eg
<|soss|><|sot|>Computing an expression? But it's static :(<|eot|><|sost|>Despite being theoretically a programming language, PHP will not allow you to use an expression when constructing a static member variable. class Bla { private static $_thing = array( 'path' => BASE_PATH . '/relative/path' ); } This dies with "syntax error, unexpected '.', expected ')'". Apparently, actually computing the value of expressions is too much for this language. I am starting to suspect they're doing it intentionally so that their new releases have cool new features to advertise.<|eost|><|sor|>How about: define('FOO_PATH', BASE_PATH . '/relative/path'); class Bla { private static $_thing = array( 'path' => FOO_PATH ); } <|eor|><|eoss|><|endoftext|>
5
lolphp
nyamsprod
5zkn29
<|soss|><|sot|>What the hell with iterator_apply ?<|eot|><|sost|>So my question is if iterator_apply is suppose to be the equivalent of array_walk why am I required to give twice the iterator to this function how does it works ??? Even the manual page does not explain it ? Is it magic ? https://3v4l.org/LYPWp <|eost|><|eoss|><|endoftext|>
26
lolphp
andsens
dez4fpn
<|soss|><|sot|>What the hell with iterator_apply ?<|eot|><|sost|>So my question is if iterator_apply is suppose to be the equivalent of array_walk why am I required to give twice the iterator to this function how does it works ??? Even the manual page does not explain it ? Is it magic ? https://3v4l.org/LYPWp <|eost|><|sor|>Wow, this is just... that functions imitates `map()`from sane languages the way a 4 year old girl uses makeup to imitate Lady Gaga.<|eor|><|eoss|><|endoftext|>
21
lolphp
the_alias_of_andrea
dez95um
<|soss|><|sot|>What the hell with iterator_apply ?<|eot|><|sost|>So my question is if iterator_apply is suppose to be the equivalent of array_walk why am I required to give twice the iterator to this function how does it works ??? Even the manual page does not explain it ? Is it magic ? https://3v4l.org/LYPWp <|eost|><|sor|>Wow. `foreach` does more for you. Wouldn't you just use that?<|eor|><|eoss|><|endoftext|>
10
lolphp
nikic
dezcu4c
<|soss|><|sot|>What the hell with iterator_apply ?<|eot|><|sost|>So my question is if iterator_apply is suppose to be the equivalent of array_walk why am I required to give twice the iterator to this function how does it works ??? Even the manual page does not explain it ? Is it magic ? https://3v4l.org/LYPWp <|eost|><|sor|>Wow. `foreach` does more for you. Wouldn't you just use that?<|eor|><|sor|>Wow indeed. This function looks extremely useless. It does the same as `foreach` in a very complicated and inefficient way. Maybe this one should be part of the next deprecation round...<|eor|><|eoss|><|endoftext|>
10
lolphp
kovensky
df01x8s
<|soss|><|sot|>What the hell with iterator_apply ?<|eot|><|sost|>So my question is if iterator_apply is suppose to be the equivalent of array_walk why am I required to give twice the iterator to this function how does it works ??? Even the manual page does not explain it ? Is it magic ? https://3v4l.org/LYPWp <|eost|><|sor|>That is actually one of the cases where PHP tries to behaves sanely and fails. What you have is not an array that you can do random access in, but an Iterator, a (potentially infinite) sequence of values. If you have already exhausted the iterator, there is no way to rewind it other than making a new one, otherwise you would need infinite memory to save all results. Anyway, the second time you try to iterate an exhausted iterator, it should do nothing and return, but it pulls three iterations out of... /dev/zero? /dev/wtf? Also, in your second call, assuming this behaves like JavaScript function application, you are giving an unrelated iterator to your iteration callback. The unrelated iterator is never advanced, so you get the first value 3 times.<|eor|><|eoss|><|endoftext|>
6
lolphp
nyamsprod
dezaa5s
<|soss|><|sot|>What the hell with iterator_apply ?<|eot|><|sost|>So my question is if iterator_apply is suppose to be the equivalent of array_walk why am I required to give twice the iterator to this function how does it works ??? Even the manual page does not explain it ? Is it magic ? https://3v4l.org/LYPWp <|eost|><|sor|>Wow. `foreach` does more for you. Wouldn't you just use that?<|eor|><|soopr|>yep it would but I still want to understand the logic behind `iterator_apply` just out of curiosity<|eoopr|><|eoss|><|endoftext|>
6
lolphp
bj_christianson
df05tsn
<|soss|><|sot|>What the hell with iterator_apply ?<|eot|><|sost|>So my question is if iterator_apply is suppose to be the equivalent of array_walk why am I required to give twice the iterator to this function how does it works ??? Even the manual page does not explain it ? Is it magic ? https://3v4l.org/LYPWp <|eost|><|sor|>That is actually one of the cases where PHP tries to behaves sanely and fails. What you have is not an array that you can do random access in, but an Iterator, a (potentially infinite) sequence of values. If you have already exhausted the iterator, there is no way to rewind it other than making a new one, otherwise you would need infinite memory to save all results. Anyway, the second time you try to iterate an exhausted iterator, it should do nothing and return, but it pulls three iterations out of... /dev/zero? /dev/wtf? Also, in your second call, assuming this behaves like JavaScript function application, you are giving an unrelated iterator to your iteration callback. The unrelated iterator is never advanced, so you get the first value 3 times.<|eor|><|sor|>[An Iterator can be rewound.](https://secure.php.net/manual/en/iterator.rewind.php) Iterator Apply does rewind the iterator with the example that applys all the twenties. The problem is that the rewound iterator is advanced, but not the iterator that's actually being operated on. There are three elements in `$iterator`, so it calls the function on `$iteratorbis` three times. But `$iteratorbis` is never advanced. The next time, `$iteratorbis` is used to run the the function, so it gets rewound, and therefore can iterate three times. But now the problem is that `$iterator` doesnt get rewound. So each loop through `$iteratorbis` tries to operate on `$iterator->current()`, [which is NULL](https://3v4l.org/iObUo). The value then gets coerced to zero for the math operation.<|eor|><|eoss|><|endoftext|>
5
lolphp
idontlikethisname
2eqpmq
<|soss|><|sot|>If you return an object from a function, you can't access its class constants directly, you have to save it to a variable first<|eot|><|sost|> <?php class Foo { const BAR = 'bar'; var $other = 'test'; } function getFoo() { return new Foo(); } var_dump(getFoo()->other); // string(4) "test" var_dump(getFoo()::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) var_dump((getFoo())::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) $foo = getFoo(); var_dump($foo->other); // string(4) "test" var_dump($foo::BAR); // string(3) "bar" I don't know why it works this way.<|eost|><|eoss|><|endoftext|>
27
lolphp
poizan42
ck21q3w
<|soss|><|sot|>If you return an object from a function, you can't access its class constants directly, you have to save it to a variable first<|eot|><|sost|> <?php class Foo { const BAR = 'bar'; var $other = 'test'; } function getFoo() { return new Foo(); } var_dump(getFoo()->other); // string(4) "test" var_dump(getFoo()::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) var_dump((getFoo())::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) $foo = getFoo(); var_dump($foo->other); // string(4) "test" var_dump($foo::BAR); // string(3) "bar" I don't know why it works this way.<|eost|><|sor|>Because their parser is an incoherent mess. They somehow can't figure out how to write a single production rule such as `EXPR := EXPR '::' ID | EXPR '[' EXPR ']' | EXPR '->' EXPR` | ... Instead they write a single one for every combination of syntax. Of course they forget some of them all the time. Note that `getFoo()->other` also used to emit a parse error - as well as `getFoo()[42]`. I think it was explained somewhere else that part of the reason for this is that they don't generate an AST but are instead emitting bytecode directly from the parser actions.<|eor|><|eoss|><|endoftext|>
22
lolphp
nikic
ck21nkf
<|soss|><|sot|>If you return an object from a function, you can't access its class constants directly, you have to save it to a variable first<|eot|><|sost|> <?php class Foo { const BAR = 'bar'; var $other = 'test'; } function getFoo() { return new Foo(); } var_dump(getFoo()->other); // string(4) "test" var_dump(getFoo()::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) var_dump((getFoo())::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) $foo = getFoo(); var_dump($foo->other); // string(4) "test" var_dump($foo::BAR); // string(3) "bar" I don't know why it works this way.<|eost|><|sor|>Fixed in PHP 7, see [uniform variable syntax](https://wiki.php.net/rfc/uniform_variable_syntax).<|eor|><|eoss|><|endoftext|>
13
lolphp
urquan
ck2iu1t
<|soss|><|sot|>If you return an object from a function, you can't access its class constants directly, you have to save it to a variable first<|eot|><|sost|> <?php class Foo { const BAR = 'bar'; var $other = 'test'; } function getFoo() { return new Foo(); } var_dump(getFoo()->other); // string(4) "test" var_dump(getFoo()::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) var_dump((getFoo())::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) $foo = getFoo(); var_dump($foo->other); // string(4) "test" var_dump($foo::BAR); // string(3) "bar" I don't know why it works this way.<|eost|><|sor|>> T_PAAMAYIM_NEKUDOTAYIM win<|eor|><|eoss|><|endoftext|>
11
lolphp
Regimardyl
ck25xuv
<|soss|><|sot|>If you return an object from a function, you can't access its class constants directly, you have to save it to a variable first<|eot|><|sost|> <?php class Foo { const BAR = 'bar'; var $other = 'test'; } function getFoo() { return new Foo(); } var_dump(getFoo()->other); // string(4) "test" var_dump(getFoo()::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) var_dump((getFoo())::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) $foo = getFoo(); var_dump($foo->other); // string(4) "test" var_dump($foo::BAR); // string(3) "bar" I don't know why it works this way.<|eost|><|sor|>Because their parser is an incoherent mess. They somehow can't figure out how to write a single production rule such as `EXPR := EXPR '::' ID | EXPR '[' EXPR ']' | EXPR '->' EXPR` | ... Instead they write a single one for every combination of syntax. Of course they forget some of them all the time. Note that `getFoo()->other` also used to emit a parse error - as well as `getFoo()[42]`. I think it was explained somewhere else that part of the reason for this is that they don't generate an AST but are instead emitting bytecode directly from the parser actions.<|eor|><|sor|>AFAIK that's also why you can't directly call closures, so if `bla()` returns a function without any parameter, then `bla()()` doesn't allow you to call it; you need to assign it to something first.<|eor|><|eoss|><|endoftext|>
11
lolphp
callcifer
ck24skd
<|soss|><|sot|>If you return an object from a function, you can't access its class constants directly, you have to save it to a variable first<|eot|><|sost|> <?php class Foo { const BAR = 'bar'; var $other = 'test'; } function getFoo() { return new Foo(); } var_dump(getFoo()->other); // string(4) "test" var_dump(getFoo()::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) var_dump((getFoo())::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) $foo = getFoo(); var_dump($foo->other); // string(4) "test" var_dump($foo::BAR); // string(3) "bar" I don't know why it works this way.<|eost|><|sor|>Fixed in PHP 7, see [uniform variable syntax](https://wiki.php.net/rfc/uniform_variable_syntax).<|eor|><|sor|>> Fixed in PHP 7 Coming soon in 2016, or, if you are using a stable environment like Debian/RHEL, 2017 :) Seriously though, I'm really glad this is finally fixed. I just wish it became part of 5.x.<|eor|><|eoss|><|endoftext|>
9
lolphp
Copex
ck22rjs
<|soss|><|sot|>If you return an object from a function, you can't access its class constants directly, you have to save it to a variable first<|eot|><|sost|> <?php class Foo { const BAR = 'bar'; var $other = 'test'; } function getFoo() { return new Foo(); } var_dump(getFoo()->other); // string(4) "test" var_dump(getFoo()::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) var_dump((getFoo())::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) $foo = getFoo(); var_dump($foo->other); // string(4) "test" var_dump($foo::BAR); // string(3) "bar" I don't know why it works this way.<|eost|><|sor|>> `var $other = 'test';` /r/lolOP<|eor|><|eoss|><|endoftext|>
8
lolphp
Banane9
ck5aygp
<|soss|><|sot|>If you return an object from a function, you can't access its class constants directly, you have to save it to a variable first<|eot|><|sost|> <?php class Foo { const BAR = 'bar'; var $other = 'test'; } function getFoo() { return new Foo(); } var_dump(getFoo()->other); // string(4) "test" var_dump(getFoo()::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) var_dump((getFoo())::BAR); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) $foo = getFoo(); var_dump($foo->other); // string(4) "test" var_dump($foo::BAR); // string(3) "bar" I don't know why it works this way.<|eost|><|sor|>Because their parser is an incoherent mess. They somehow can't figure out how to write a single production rule such as `EXPR := EXPR '::' ID | EXPR '[' EXPR ']' | EXPR '->' EXPR` | ... Instead they write a single one for every combination of syntax. Of course they forget some of them all the time. Note that `getFoo()->other` also used to emit a parse error - as well as `getFoo()[42]`. I think it was explained somewhere else that part of the reason for this is that they don't generate an AST but are instead emitting bytecode directly from the parser actions.<|eor|><|sor|>AFAIK that's also why you can't directly call closures, so if `bla()` returns a function without any parameter, then `bla()()` doesn't allow you to call it; you need to assign it to something first.<|eor|><|sor|>Also fixed in PHP 7, btw.<|eor|><|sor|>Shouldn't have been broken in the first place...<|eor|><|eoss|><|endoftext|>
6
lolphp
tinkermake
24vpjd
<|sols|><|sot|>Just in case... Thought you guys might be interested<|eot|><|sol|>https://hackerone.com/php<|eol|><|eols|><|endoftext|>
25
lolphp
dongilbert
23zchf
<|sols|><|sot|>Bug fixed 5 years ago lives on (x-post /r/php)<|eot|><|sol|>http://www.reddit.com/r/PHP/comments/23zcdj/bug_in_mysqli_scumbagphp/<|eol|><|eols|><|endoftext|>
25
lolphp
michaelpb
ch2l08u
<|sols|><|sot|>Bug fixed 5 years ago lives on (x-post /r/php)<|eot|><|sol|>http://www.reddit.com/r/PHP/comments/23zcdj/bug_in_mysqli_scumbagphp/<|eol|><|sor|>So they "fixed" the bug by putting it into the documentation. *Brilliant*. No sensible language would set the properties of an object *before it was created*.<|eor|><|sor|>And deleting the tests that failed https://github.com/php/php-src/commit/eb0de2af90bf4b2f07b56d48355e02b73e4c7ee4<|eor|><|eols|><|endoftext|>
11
lolphp
Banane9
ch2e8yw
<|sols|><|sot|>Bug fixed 5 years ago lives on (x-post /r/php)<|eot|><|sol|>http://www.reddit.com/r/PHP/comments/23zcdj/bug_in_mysqli_scumbagphp/<|eol|><|sor|>So they "fixed" the bug by putting it into the documentation. *Brilliant*. No sensible language would set the properties of an object *before it was created*.<|eor|><|eols|><|endoftext|>
9
lolphp
tr4ce
1q3r30
<|sols|><|sot|>More $string++ craziness<|eot|><|sol|>https://eval.in/61309<|eol|><|eols|><|endoftext|>
23
lolphp
ajmarks
cd90n6r
<|sols|><|sot|>More $string++ craziness<|eot|><|sol|>https://eval.in/61309<|eol|><|sor|>Dupe: http://www.reddit.com/r/lolphp/comments/1ofw7t/2d9/<|eor|><|eols|><|endoftext|>
8
lolphp
suspiciously_calm
cd96wok
<|sols|><|sot|>More $string++ craziness<|eot|><|sol|>https://eval.in/61309<|eol|><|sor|>Dupe: http://www.reddit.com/r/lolphp/comments/1ofw7t/2d9/<|eor|><|sor|>Yep, it's not "more `$string++` craziness," it's exactly the same.<|eor|><|eols|><|endoftext|>
6
lolphp
hyrulz
1etq3n
<|soss|><|sot|>Wordpress will automatically convert foo to $foo for you.<|eot|><|sost|>Give it a try. A warning will be given when enabling debug mode in wp-config.php: define('WP_DEBUG', true); <|eost|><|eoss|><|endoftext|>
27
lolphp
gearvOsh
ca41bby
<|soss|><|sot|>Wordpress will automatically convert foo to $foo for you.<|eot|><|sost|>Give it a try. A warning will be given when enabling debug mode in wp-config.php: define('WP_DEBUG', true); <|eost|><|sor|>Well, Wordpress is a whole is LOL.<|eor|><|eoss|><|endoftext|>
19
lolphp
redalastor
ca61fy6
<|soss|><|sot|>Wordpress will automatically convert foo to $foo for you.<|eot|><|sost|>Give it a try. A warning will be given when enabling debug mode in wp-config.php: define('WP_DEBUG', true); <|eost|><|sor|>Wordpress <> PHP<|eor|><|sor|>You've got a syntax error $wordpress != $php EDIT: Didn't realize what subreddit I was in.<|eor|><|sor|>Many languages use <> for !=, not sure what your point is?<|eor|><|sor|>Initially, I thought this was a wordpress subreddit, meaning that the language was PHP. PHP uses !=. Then, I realized this was a PHP subreddit... and PHP still uses !=. No offense was meant... it was just a bad joke. <|eor|><|sor|>No offense taken. Just so you know, PHP uses != or <> interchangeably. http://us2.php.net/manual/en/language.operators.comparison.php<|eor|><|sor|>Wow... I had absolutely no idea. I just assumed. Thanks for pointing that out.<|eor|><|sor|>Never start by assuming that PHP is sane. :)<|eor|><|eoss|><|endoftext|>
17
lolphp
David_Crockett
ca405cm
<|soss|><|sot|>Wordpress will automatically convert foo to $foo for you.<|eot|><|sost|>Give it a try. A warning will be given when enabling debug mode in wp-config.php: define('WP_DEBUG', true); <|eost|><|sor|>Wordpress <> PHP<|eor|><|eoss|><|endoftext|>
15
lolphp
David_Crockett
ca49yck
<|soss|><|sot|>Wordpress will automatically convert foo to $foo for you.<|eot|><|sost|>Give it a try. A warning will be given when enabling debug mode in wp-config.php: define('WP_DEBUG', true); <|eost|><|sor|>Wordpress <> PHP<|eor|><|sor|>You've got a syntax error $wordpress != $php EDIT: Didn't realize what subreddit I was in.<|eor|><|sor|>Many languages use <> for !=, not sure what your point is?<|eor|><|sor|>Initially, I thought this was a wordpress subreddit, meaning that the language was PHP. PHP uses !=. Then, I realized this was a PHP subreddit... and PHP still uses !=. No offense was meant... it was just a bad joke. <|eor|><|sor|>No offense taken. Just so you know, PHP uses != or <> interchangeably. http://us2.php.net/manual/en/language.operators.comparison.php<|eor|><|eoss|><|endoftext|>
15
lolphp
devourer09
ca9ckhh
<|soss|><|sot|>Wordpress will automatically convert foo to $foo for you.<|eot|><|sost|>Give it a try. A warning will be given when enabling debug mode in wp-config.php: define('WP_DEBUG', true); <|eost|><|sor|>You've got a syntax error $wordpress != $php EDIT: Didn't realize what subreddit I was in.<|eor|><|sor|>Many languages use <> for !=, not sure what your point is?<|eor|><|sor|>Initially, I thought this was a wordpress subreddit, meaning that the language was PHP. PHP uses !=. Then, I realized this was a PHP subreddit... and PHP still uses !=. No offense was meant... it was just a bad joke. <|eor|><|sor|>No offense taken. Just so you know, PHP uses != or <> interchangeably. http://us2.php.net/manual/en/language.operators.comparison.php<|eor|><|sor|>Wow... I had absolutely no idea. I just assumed. Thanks for pointing that out.<|eor|><|sor|>Never start by assuming that PHP is sane. :)<|eor|><|sor|>I wont call the `<>` thing sane for non-maths. `!` to negate something is the standard practice. Of course, I would want to see `` more, but some stuff still hates unicode in 2013.<|eor|><|sor|>I was born with a rare genetic disorder. Whenever unicode characters are used IRL I only see question marks and rectangles.<|eor|><|eoss|><|endoftext|>
10
lolphp
quirk
ca46ui8
<|soss|><|sot|>Wordpress will automatically convert foo to $foo for you.<|eot|><|sost|>Give it a try. A warning will be given when enabling debug mode in wp-config.php: define('WP_DEBUG', true); <|eost|><|sor|>Wordpress <> PHP<|eor|><|sor|>You've got a syntax error $wordpress != $php EDIT: Didn't realize what subreddit I was in.<|eor|><|eoss|><|endoftext|>
8
lolphp
quirk
ca4a2kf
<|soss|><|sot|>Wordpress will automatically convert foo to $foo for you.<|eot|><|sost|>Give it a try. A warning will be given when enabling debug mode in wp-config.php: define('WP_DEBUG', true); <|eost|><|sor|>Wordpress <> PHP<|eor|><|sor|>You've got a syntax error $wordpress != $php EDIT: Didn't realize what subreddit I was in.<|eor|><|sor|>Many languages use <> for !=, not sure what your point is?<|eor|><|sor|>Initially, I thought this was a wordpress subreddit, meaning that the language was PHP. PHP uses !=. Then, I realized this was a PHP subreddit... and PHP still uses !=. No offense was meant... it was just a bad joke. <|eor|><|sor|>No offense taken. Just so you know, PHP uses != or <> interchangeably. http://us2.php.net/manual/en/language.operators.comparison.php<|eor|><|sor|>Wow... I had absolutely no idea. I just assumed. Thanks for pointing that out.<|eor|><|eoss|><|endoftext|>
8
lolphp
jawn-
1eqt0a
<|soss|><|sot|>fun with json_encode and arrays<|eot|><|sost|> $ cat test.php <?php echo json_encode(array('1' => 1) ), "\n"; echo json_encode(array('0' => 1)); ?> $ php test.php {"1":1} [1] loose typing shittiness strikes again. <|eost|><|eoss|><|endoftext|>
25
lolphp
lost_fogs
ca2wv4y
<|soss|><|sot|>fun with json_encode and arrays<|eot|><|sost|> $ cat test.php <?php echo json_encode(array('1' => 1) ), "\n"; echo json_encode(array('0' => 1)); ?> $ php test.php {"1":1} [1] loose typing shittiness strikes again. <|eost|><|sor|>Does Javascript even allow non-zero based arrays? I'm pretty sure the index order gets reset every time an array function is called, and fills up all the missing indices. So basically, this makes sense.<|eor|><|sor|>This does not make sense. I dare you, I double dare you, to generate using json_encode this perfectly fine JSON object: { "0": 1 }<|eor|><|sor|>Here you go: <? $ob = new stdClass; $ob->{0} = 1; echo json_encode($ob); ?> **Edit:** Also, `json_encode((object)array(1));`<|eor|><|eoss|><|endoftext|>
22
lolphp
InsaneWookie
ca2uha6
<|soss|><|sot|>fun with json_encode and arrays<|eot|><|sost|> $ cat test.php <?php echo json_encode(array('1' => 1) ), "\n"; echo json_encode(array('0' => 1)); ?> $ php test.php {"1":1} [1] loose typing shittiness strikes again. <|eost|><|sor|>Yip that does't seem right. The real LOLPHP here is that it turns out you can't define an array key as a integer string. ie array('0' => 'foo') becomes array(0 => 'foo') After that happens it follows the behaviour in example #3 from http://php.net/manual/en/function.json-encode.php That is 0 indexed arrays are converted to an json array. non zero indexed arrays are converted to a json object. <|eor|><|eoss|><|endoftext|>
14
lolphp
midir
ca2zbzd
<|soss|><|sot|>fun with json_encode and arrays<|eot|><|sost|> $ cat test.php <?php echo json_encode(array('1' => 1) ), "\n"; echo json_encode(array('0' => 1)); ?> $ php test.php {"1":1} [1] loose typing shittiness strikes again. <|eost|><|sor|>Inelegant, but an inevitable consequence of PHP & JavaScript's different flavors of arrays.<|eor|><|eoss|><|endoftext|>
11
lolphp
vytah
ca2vmv2
<|soss|><|sot|>fun with json_encode and arrays<|eot|><|sost|> $ cat test.php <?php echo json_encode(array('1' => 1) ), "\n"; echo json_encode(array('0' => 1)); ?> $ php test.php {"1":1} [1] loose typing shittiness strikes again. <|eost|><|sor|>Does Javascript even allow non-zero based arrays? I'm pretty sure the index order gets reset every time an array function is called, and fills up all the missing indices. So basically, this makes sense.<|eor|><|sor|>This does not make sense. I dare you, I double dare you, to generate using json_encode this perfectly fine JSON object: { "0": 1 }<|eor|><|eoss|><|endoftext|>
6
lolphp
gearvOsh
ca2vbw0
<|soss|><|sot|>fun with json_encode and arrays<|eot|><|sost|> $ cat test.php <?php echo json_encode(array('1' => 1) ), "\n"; echo json_encode(array('0' => 1)); ?> $ php test.php {"1":1} [1] loose typing shittiness strikes again. <|eost|><|sor|>Does Javascript even allow non-zero based arrays? I'm pretty sure the index order gets reset every time an array function is called, and fills up all the missing indices. So basically, this makes sense.<|eor|><|eoss|><|endoftext|>
5
lolphp
barubary
qqq3wm
<|soss|><|sot|>Cheap shot: PHP release dates<|eot|><|sost|>Recently I had occasion to look at PHP's official release history at https://www.php.net/releases/index.php, specifically version 7.0.0 and following. ~~(I'd give you a link to the exact location, but the PHP website doesn't believe in `id` attributes.)~~ See [this link to see what I mean](https://www.php.net/releases/index.php#7.0.2). The salient points: > ## 7.0.2 > > - Released: 07 Jan 2015 > - [...] > > ## 7.0.1 > > - Released: 17 Dec 2015 > - [...] > > ## 7.0.0 > > - Released: 03 Dec 2015 > - [...] It looks like the 7.0.2 release included a time machine because it managed to take place 11 months before 7.0.1 and 7.0.0. (Yeah, it's just a typo, but I still had to search around to figure out which dates are the wrong ones.)<|eost|><|eoss|><|endoftext|>
25
lolphp
tdammers
hk1zik1
<|soss|><|sot|>Cheap shot: PHP release dates<|eot|><|sost|>Recently I had occasion to look at PHP's official release history at https://www.php.net/releases/index.php, specifically version 7.0.0 and following. ~~(I'd give you a link to the exact location, but the PHP website doesn't believe in `id` attributes.)~~ See [this link to see what I mean](https://www.php.net/releases/index.php#7.0.2). The salient points: > ## 7.0.2 > > - Released: 07 Jan 2015 > - [...] > > ## 7.0.1 > > - Released: 17 Dec 2015 > - [...] > > ## 7.0.0 > > - Released: 03 Dec 2015 > - [...] It looks like the 7.0.2 release included a time machine because it managed to take place 11 months before 7.0.1 and 7.0.0. (Yeah, it's just a typo, but I still had to search around to figure out which dates are the wrong ones.)<|eost|><|sor|>Would be funny if it were caused by PHP's timezone handling code. But probably just a legit typo.<|eor|><|eoss|><|endoftext|>
26
lolphp
Decicus
hk1t7ni
<|soss|><|sot|>Cheap shot: PHP release dates<|eot|><|sost|>Recently I had occasion to look at PHP's official release history at https://www.php.net/releases/index.php, specifically version 7.0.0 and following. ~~(I'd give you a link to the exact location, but the PHP website doesn't believe in `id` attributes.)~~ See [this link to see what I mean](https://www.php.net/releases/index.php#7.0.2). The salient points: > ## 7.0.2 > > - Released: 07 Jan 2015 > - [...] > > ## 7.0.1 > > - Released: 17 Dec 2015 > - [...] > > ## 7.0.0 > > - Released: 03 Dec 2015 > - [...] It looks like the 7.0.2 release included a time machine because it managed to take place 11 months before 7.0.1 and 7.0.0. (Yeah, it's just a typo, but I still had to search around to figure out which dates are the wrong ones.)<|eost|><|sor|>> (I'd give you a link to the exact location, but the PHP website doesn't believe in `id` attributes.) Works for me: https://www.php.net/releases/index.php#7.0.2<|eor|><|eoss|><|endoftext|>
8
lolphp
postmodest
hk4iji0
<|soss|><|sot|>Cheap shot: PHP release dates<|eot|><|sost|>Recently I had occasion to look at PHP's official release history at https://www.php.net/releases/index.php, specifically version 7.0.0 and following. ~~(I'd give you a link to the exact location, but the PHP website doesn't believe in `id` attributes.)~~ See [this link to see what I mean](https://www.php.net/releases/index.php#7.0.2). The salient points: > ## 7.0.2 > > - Released: 07 Jan 2015 > - [...] > > ## 7.0.1 > > - Released: 17 Dec 2015 > - [...] > > ## 7.0.0 > > - Released: 03 Dec 2015 > - [...] It looks like the 7.0.2 release included a time machine because it managed to take place 11 months before 7.0.1 and 7.0.0. (Yeah, it's just a typo, but I still had to search around to figure out which dates are the wrong ones.)<|eost|><|sor|>> (I'd give you a link to the exact location, but the PHP website doesn't believe in `id` attributes.) Works for me: https://www.php.net/releases/index.php#7.0.2<|eor|><|soopr|>Oh, interesting. You're right. I got confused because I only inspected the `h2` and below, but there is an invisible `a` element just before that, and *that* has an `id` attribute. In a way this is halfway between the old way of doing things where you have an invisible `<a name="foo"></a>` element next to the link target, and the "modern" (HTML 4, 1998?) way of doing things where you just put an `id` attribute on the link target.<|eoopr|><|sor|>This reminds me: I hate html5 and the whatwg. Im gonna start /r/lolwhatwg<|eor|><|eoss|><|endoftext|>
6
lolphp
barubary
itelin
<|soss|><|sot|>What even is Callable?<|eot|><|sost|>*(Inspired by [this post](/r/lolphp/comments/iqlpur/set_exception_handler_returns_null_on_error_and/).)* The [documentation for `set_exception_handler`](https://www.php.net/manual/en/function.set-exception-handler.php) shows this signature: > set_exception_handler ( callable $exception_handler ) : callable OK, so it requires the argument to be `callable` and returns a `callable`. Except ... > `NULL` may be passed instead, to reset this handler to its default state. > [...] > Returns the name of the previously defined exception handler, or `NULL` on error. Wait, since when is `NULL` callable? (NULL)(); As [PHP itself says](https://3v4l.org/QQJco): `Value of type null is not callable` So that function signature was a lie. --- But wait, what was that? "_Returns **the name** of the previously defined exception handler_"? I know *[object, method]* pairs are callable. Does that mean if I do `set_exception_handler([$obj, 'foo'])` and then call `set_exception_handler` again, it will return the name of the method (`'foo'`)? class Bar { function foo($ex) {} } $obj = new Bar; set_exception_handler([$obj, 'foo']); echo set_exception_handler(NULL), "\n"; The [answer is no](https://3v4l.org/bp3IF): > Array The callable I passed in does not have a name (it's a plain array), so `set_exception_handler` can't keep what its documentation promises. --- But wait, what exactly counts as "callable"? [The documentation](https://www.php.net/manual/en/language.types.callable.php) helpfully provides a list of the possible options: 1. A string containing the name of a function (built in or user-defined). 2. A string containing two names separated by `::`, such as `foo::bar`, which is equivalent to `['foo', 'bar']` (see below). 3. An array of two elements, the first being an object and the second a string containing the name of a method, representing a method call on the object. 4. An array of two elements, the first being a string containing a class name and the second a string containing a method name, representing a method call on the class. 5. An anonymous function, i.e. a value created by a `function () { ... }` expression (which is secretly an instance of the `Closure` class under the hood). (As expected, `NULL` is not on the list.) From this list I would expect something like `set_exception_handler(new Foo)` to fail. The argument `new Foo` is clearly an object instance, not a string or array or anonymous function. And yet: class Foo { function __invoke($x) { echo "invoked with $x\n"; } } set_exception_handler(new Foo); throw new Error("dingus"); [Output](https://3v4l.org/GqIjq): > invoked with Error: dingus Either the documentation of `set_exception_handler` is wrong and the function accepts values that are not callable, or objects can be callable and the documentation of `Callable` is wrong. Or maybe the implementation is wrong and this code isn't supposed to work. I don't know enough about PHP to tell which one it is.<|eost|><|eoss|><|endoftext|>
23
lolphp
Schmittfried
g5egr4n
<|soss|><|sot|>What even is Callable?<|eot|><|sost|>*(Inspired by [this post](/r/lolphp/comments/iqlpur/set_exception_handler_returns_null_on_error_and/).)* The [documentation for `set_exception_handler`](https://www.php.net/manual/en/function.set-exception-handler.php) shows this signature: > set_exception_handler ( callable $exception_handler ) : callable OK, so it requires the argument to be `callable` and returns a `callable`. Except ... > `NULL` may be passed instead, to reset this handler to its default state. > [...] > Returns the name of the previously defined exception handler, or `NULL` on error. Wait, since when is `NULL` callable? (NULL)(); As [PHP itself says](https://3v4l.org/QQJco): `Value of type null is not callable` So that function signature was a lie. --- But wait, what was that? "_Returns **the name** of the previously defined exception handler_"? I know *[object, method]* pairs are callable. Does that mean if I do `set_exception_handler([$obj, 'foo'])` and then call `set_exception_handler` again, it will return the name of the method (`'foo'`)? class Bar { function foo($ex) {} } $obj = new Bar; set_exception_handler([$obj, 'foo']); echo set_exception_handler(NULL), "\n"; The [answer is no](https://3v4l.org/bp3IF): > Array The callable I passed in does not have a name (it's a plain array), so `set_exception_handler` can't keep what its documentation promises. --- But wait, what exactly counts as "callable"? [The documentation](https://www.php.net/manual/en/language.types.callable.php) helpfully provides a list of the possible options: 1. A string containing the name of a function (built in or user-defined). 2. A string containing two names separated by `::`, such as `foo::bar`, which is equivalent to `['foo', 'bar']` (see below). 3. An array of two elements, the first being an object and the second a string containing the name of a method, representing a method call on the object. 4. An array of two elements, the first being a string containing a class name and the second a string containing a method name, representing a method call on the class. 5. An anonymous function, i.e. a value created by a `function () { ... }` expression (which is secretly an instance of the `Closure` class under the hood). (As expected, `NULL` is not on the list.) From this list I would expect something like `set_exception_handler(new Foo)` to fail. The argument `new Foo` is clearly an object instance, not a string or array or anonymous function. And yet: class Foo { function __invoke($x) { echo "invoked with $x\n"; } } set_exception_handler(new Foo); throw new Error("dingus"); [Output](https://3v4l.org/GqIjq): > invoked with Error: dingus Either the documentation of `set_exception_handler` is wrong and the function accepts values that are not callable, or objects can be callable and the documentation of `Callable` is wrong. Or maybe the implementation is wrong and this code isn't supposed to work. I don't know enough about PHP to tell which one it is.<|eost|><|sor|>For any typed parameter you may return or use NULL. You may treat any "the type must be foo" as "the type must be foo, or null." This is no exception.<|eor|><|soopr|>Interesting. Is that documented anywhere?<|eoopr|><|sor|>No, because it's wrong.<|eor|><|eoss|><|endoftext|>
13
lolphp
duskwuff
g5eg1n2
<|soss|><|sot|>What even is Callable?<|eot|><|sost|>*(Inspired by [this post](/r/lolphp/comments/iqlpur/set_exception_handler_returns_null_on_error_and/).)* The [documentation for `set_exception_handler`](https://www.php.net/manual/en/function.set-exception-handler.php) shows this signature: > set_exception_handler ( callable $exception_handler ) : callable OK, so it requires the argument to be `callable` and returns a `callable`. Except ... > `NULL` may be passed instead, to reset this handler to its default state. > [...] > Returns the name of the previously defined exception handler, or `NULL` on error. Wait, since when is `NULL` callable? (NULL)(); As [PHP itself says](https://3v4l.org/QQJco): `Value of type null is not callable` So that function signature was a lie. --- But wait, what was that? "_Returns **the name** of the previously defined exception handler_"? I know *[object, method]* pairs are callable. Does that mean if I do `set_exception_handler([$obj, 'foo'])` and then call `set_exception_handler` again, it will return the name of the method (`'foo'`)? class Bar { function foo($ex) {} } $obj = new Bar; set_exception_handler([$obj, 'foo']); echo set_exception_handler(NULL), "\n"; The [answer is no](https://3v4l.org/bp3IF): > Array The callable I passed in does not have a name (it's a plain array), so `set_exception_handler` can't keep what its documentation promises. --- But wait, what exactly counts as "callable"? [The documentation](https://www.php.net/manual/en/language.types.callable.php) helpfully provides a list of the possible options: 1. A string containing the name of a function (built in or user-defined). 2. A string containing two names separated by `::`, such as `foo::bar`, which is equivalent to `['foo', 'bar']` (see below). 3. An array of two elements, the first being an object and the second a string containing the name of a method, representing a method call on the object. 4. An array of two elements, the first being a string containing a class name and the second a string containing a method name, representing a method call on the class. 5. An anonymous function, i.e. a value created by a `function () { ... }` expression (which is secretly an instance of the `Closure` class under the hood). (As expected, `NULL` is not on the list.) From this list I would expect something like `set_exception_handler(new Foo)` to fail. The argument `new Foo` is clearly an object instance, not a string or array or anonymous function. And yet: class Foo { function __invoke($x) { echo "invoked with $x\n"; } } set_exception_handler(new Foo); throw new Error("dingus"); [Output](https://3v4l.org/GqIjq): > invoked with Error: dingus Either the documentation of `set_exception_handler` is wrong and the function accepts values that are not callable, or objects can be callable and the documentation of `Callable` is wrong. Or maybe the implementation is wrong and this code isn't supposed to work. I don't know enough about PHP to tell which one it is.<|eost|><|sor|>> So that function signature was a lie. A lot of signatures for builtin functions haven't been updated to use newer typing features like nullable types or (in PHP8) union types yet. Give it time.<|eor|><|eoss|><|endoftext|>
8
lolphp
the_alias_of_andrea
g5ecjng
<|soss|><|sot|>What even is Callable?<|eot|><|sost|>*(Inspired by [this post](/r/lolphp/comments/iqlpur/set_exception_handler_returns_null_on_error_and/).)* The [documentation for `set_exception_handler`](https://www.php.net/manual/en/function.set-exception-handler.php) shows this signature: > set_exception_handler ( callable $exception_handler ) : callable OK, so it requires the argument to be `callable` and returns a `callable`. Except ... > `NULL` may be passed instead, to reset this handler to its default state. > [...] > Returns the name of the previously defined exception handler, or `NULL` on error. Wait, since when is `NULL` callable? (NULL)(); As [PHP itself says](https://3v4l.org/QQJco): `Value of type null is not callable` So that function signature was a lie. --- But wait, what was that? "_Returns **the name** of the previously defined exception handler_"? I know *[object, method]* pairs are callable. Does that mean if I do `set_exception_handler([$obj, 'foo'])` and then call `set_exception_handler` again, it will return the name of the method (`'foo'`)? class Bar { function foo($ex) {} } $obj = new Bar; set_exception_handler([$obj, 'foo']); echo set_exception_handler(NULL), "\n"; The [answer is no](https://3v4l.org/bp3IF): > Array The callable I passed in does not have a name (it's a plain array), so `set_exception_handler` can't keep what its documentation promises. --- But wait, what exactly counts as "callable"? [The documentation](https://www.php.net/manual/en/language.types.callable.php) helpfully provides a list of the possible options: 1. A string containing the name of a function (built in or user-defined). 2. A string containing two names separated by `::`, such as `foo::bar`, which is equivalent to `['foo', 'bar']` (see below). 3. An array of two elements, the first being an object and the second a string containing the name of a method, representing a method call on the object. 4. An array of two elements, the first being a string containing a class name and the second a string containing a method name, representing a method call on the class. 5. An anonymous function, i.e. a value created by a `function () { ... }` expression (which is secretly an instance of the `Closure` class under the hood). (As expected, `NULL` is not on the list.) From this list I would expect something like `set_exception_handler(new Foo)` to fail. The argument `new Foo` is clearly an object instance, not a string or array or anonymous function. And yet: class Foo { function __invoke($x) { echo "invoked with $x\n"; } } set_exception_handler(new Foo); throw new Error("dingus"); [Output](https://3v4l.org/GqIjq): > invoked with Error: dingus Either the documentation of `set_exception_handler` is wrong and the function accepts values that are not callable, or objects can be callable and the documentation of `Callable` is wrong. Or maybe the implementation is wrong and this code isn't supposed to work. I don't know enough about PHP to tell which one it is.<|eost|><|sor|>For any typed parameter you may return or use NULL. You may treat any "the type must be foo" as "the type must be foo, or null." This is no exception.<|eor|><|soopr|>Interesting. Is that documented anywhere?<|eoopr|><|sor|>It might be, but probably not what /u/bart2019 said is not _quite_ true. Many, probably most, standard library/extension functions in PHP behave like this, though some of them handle NULL differently. By contrast this is not how userland functions work. The way this works is quite clear and uniform in the PHP source code, it's more of a documentation issue than anything else. Though it is also an inconsistency that it would be nice to get rid of. I don't remember if PHP 8 changes this or not. I know I made strict_types override this at least.<|eor|><|eoss|><|endoftext|>
7
lolphp
Takeoded
g5g4ygc
<|soss|><|sot|>What even is Callable?<|eot|><|sost|>*(Inspired by [this post](/r/lolphp/comments/iqlpur/set_exception_handler_returns_null_on_error_and/).)* The [documentation for `set_exception_handler`](https://www.php.net/manual/en/function.set-exception-handler.php) shows this signature: > set_exception_handler ( callable $exception_handler ) : callable OK, so it requires the argument to be `callable` and returns a `callable`. Except ... > `NULL` may be passed instead, to reset this handler to its default state. > [...] > Returns the name of the previously defined exception handler, or `NULL` on error. Wait, since when is `NULL` callable? (NULL)(); As [PHP itself says](https://3v4l.org/QQJco): `Value of type null is not callable` So that function signature was a lie. --- But wait, what was that? "_Returns **the name** of the previously defined exception handler_"? I know *[object, method]* pairs are callable. Does that mean if I do `set_exception_handler([$obj, 'foo'])` and then call `set_exception_handler` again, it will return the name of the method (`'foo'`)? class Bar { function foo($ex) {} } $obj = new Bar; set_exception_handler([$obj, 'foo']); echo set_exception_handler(NULL), "\n"; The [answer is no](https://3v4l.org/bp3IF): > Array The callable I passed in does not have a name (it's a plain array), so `set_exception_handler` can't keep what its documentation promises. --- But wait, what exactly counts as "callable"? [The documentation](https://www.php.net/manual/en/language.types.callable.php) helpfully provides a list of the possible options: 1. A string containing the name of a function (built in or user-defined). 2. A string containing two names separated by `::`, such as `foo::bar`, which is equivalent to `['foo', 'bar']` (see below). 3. An array of two elements, the first being an object and the second a string containing the name of a method, representing a method call on the object. 4. An array of two elements, the first being a string containing a class name and the second a string containing a method name, representing a method call on the class. 5. An anonymous function, i.e. a value created by a `function () { ... }` expression (which is secretly an instance of the `Closure` class under the hood). (As expected, `NULL` is not on the list.) From this list I would expect something like `set_exception_handler(new Foo)` to fail. The argument `new Foo` is clearly an object instance, not a string or array or anonymous function. And yet: class Foo { function __invoke($x) { echo "invoked with $x\n"; } } set_exception_handler(new Foo); throw new Error("dingus"); [Output](https://3v4l.org/GqIjq): > invoked with Error: dingus Either the documentation of `set_exception_handler` is wrong and the function accepts values that are not callable, or objects can be callable and the documentation of `Callable` is wrong. Or maybe the implementation is wrong and this code isn't supposed to work. I don't know enough about PHP to tell which one it is.<|eost|><|sor|>> So that function signature was a lie. yeah, the correct signature is: set_exception_handler ( ?callable $exception_handler ) : ?callable > Either the documentation of set_exception_handler is wrong and the function accepts values that are not callable yeah the documentation is definitely wrong, it accepts `callable and NULL` > Or maybe the implementation is wrong and this code isn't supposed to work. good question, i too don't know if `object containing an __invoke method is supposed to be callable or not` (i'm gussing the answer is `yes they're callable and the documentation for Callable is also wrong` , but i don't know for sure) > again, it will return the name of the method ('foo')? no, it returns the array you gave to set_exception_handler() previously, replace echo with var_dump and you'll see: ```php set_exception_handler([$obj, 'foo']); var_dump(set_exception_handler(NULL)); ``` outputs: ``` array(2) { [0]=> object(Bar)#1 (0) { } [1]=> string(3) "foo" } ``` that last part is sensible. > Returns the name of the previously defined exception handler yeah, no, that's bullshit, it returns null or CALLABLE (and callable may indeed be a function name, but it may also be an array, as your code shows, it may also be a closure)<|eor|><|eoss|><|endoftext|>
6
lolphp
barubary
g5e4e5f
<|soss|><|sot|>What even is Callable?<|eot|><|sost|>*(Inspired by [this post](/r/lolphp/comments/iqlpur/set_exception_handler_returns_null_on_error_and/).)* The [documentation for `set_exception_handler`](https://www.php.net/manual/en/function.set-exception-handler.php) shows this signature: > set_exception_handler ( callable $exception_handler ) : callable OK, so it requires the argument to be `callable` and returns a `callable`. Except ... > `NULL` may be passed instead, to reset this handler to its default state. > [...] > Returns the name of the previously defined exception handler, or `NULL` on error. Wait, since when is `NULL` callable? (NULL)(); As [PHP itself says](https://3v4l.org/QQJco): `Value of type null is not callable` So that function signature was a lie. --- But wait, what was that? "_Returns **the name** of the previously defined exception handler_"? I know *[object, method]* pairs are callable. Does that mean if I do `set_exception_handler([$obj, 'foo'])` and then call `set_exception_handler` again, it will return the name of the method (`'foo'`)? class Bar { function foo($ex) {} } $obj = new Bar; set_exception_handler([$obj, 'foo']); echo set_exception_handler(NULL), "\n"; The [answer is no](https://3v4l.org/bp3IF): > Array The callable I passed in does not have a name (it's a plain array), so `set_exception_handler` can't keep what its documentation promises. --- But wait, what exactly counts as "callable"? [The documentation](https://www.php.net/manual/en/language.types.callable.php) helpfully provides a list of the possible options: 1. A string containing the name of a function (built in or user-defined). 2. A string containing two names separated by `::`, such as `foo::bar`, which is equivalent to `['foo', 'bar']` (see below). 3. An array of two elements, the first being an object and the second a string containing the name of a method, representing a method call on the object. 4. An array of two elements, the first being a string containing a class name and the second a string containing a method name, representing a method call on the class. 5. An anonymous function, i.e. a value created by a `function () { ... }` expression (which is secretly an instance of the `Closure` class under the hood). (As expected, `NULL` is not on the list.) From this list I would expect something like `set_exception_handler(new Foo)` to fail. The argument `new Foo` is clearly an object instance, not a string or array or anonymous function. And yet: class Foo { function __invoke($x) { echo "invoked with $x\n"; } } set_exception_handler(new Foo); throw new Error("dingus"); [Output](https://3v4l.org/GqIjq): > invoked with Error: dingus Either the documentation of `set_exception_handler` is wrong and the function accepts values that are not callable, or objects can be callable and the documentation of `Callable` is wrong. Or maybe the implementation is wrong and this code isn't supposed to work. I don't know enough about PHP to tell which one it is.<|eost|><|sor|>For any typed parameter you may return or use NULL. You may treat any "the type must be foo" as "the type must be foo, or null." This is no exception.<|eor|><|soopr|>Interesting. Is that documented anywhere?<|eoopr|><|eoss|><|endoftext|>
6
lolphp
the_alias_of_andrea
g5gtgax
<|soss|><|sot|>What even is Callable?<|eot|><|sost|>*(Inspired by [this post](/r/lolphp/comments/iqlpur/set_exception_handler_returns_null_on_error_and/).)* The [documentation for `set_exception_handler`](https://www.php.net/manual/en/function.set-exception-handler.php) shows this signature: > set_exception_handler ( callable $exception_handler ) : callable OK, so it requires the argument to be `callable` and returns a `callable`. Except ... > `NULL` may be passed instead, to reset this handler to its default state. > [...] > Returns the name of the previously defined exception handler, or `NULL` on error. Wait, since when is `NULL` callable? (NULL)(); As [PHP itself says](https://3v4l.org/QQJco): `Value of type null is not callable` So that function signature was a lie. --- But wait, what was that? "_Returns **the name** of the previously defined exception handler_"? I know *[object, method]* pairs are callable. Does that mean if I do `set_exception_handler([$obj, 'foo'])` and then call `set_exception_handler` again, it will return the name of the method (`'foo'`)? class Bar { function foo($ex) {} } $obj = new Bar; set_exception_handler([$obj, 'foo']); echo set_exception_handler(NULL), "\n"; The [answer is no](https://3v4l.org/bp3IF): > Array The callable I passed in does not have a name (it's a plain array), so `set_exception_handler` can't keep what its documentation promises. --- But wait, what exactly counts as "callable"? [The documentation](https://www.php.net/manual/en/language.types.callable.php) helpfully provides a list of the possible options: 1. A string containing the name of a function (built in or user-defined). 2. A string containing two names separated by `::`, such as `foo::bar`, which is equivalent to `['foo', 'bar']` (see below). 3. An array of two elements, the first being an object and the second a string containing the name of a method, representing a method call on the object. 4. An array of two elements, the first being a string containing a class name and the second a string containing a method name, representing a method call on the class. 5. An anonymous function, i.e. a value created by a `function () { ... }` expression (which is secretly an instance of the `Closure` class under the hood). (As expected, `NULL` is not on the list.) From this list I would expect something like `set_exception_handler(new Foo)` to fail. The argument `new Foo` is clearly an object instance, not a string or array or anonymous function. And yet: class Foo { function __invoke($x) { echo "invoked with $x\n"; } } set_exception_handler(new Foo); throw new Error("dingus"); [Output](https://3v4l.org/GqIjq): > invoked with Error: dingus Either the documentation of `set_exception_handler` is wrong and the function accepts values that are not callable, or objects can be callable and the documentation of `Callable` is wrong. Or maybe the implementation is wrong and this code isn't supposed to work. I don't know enough about PHP to tell which one it is.<|eost|><|sor|>> So that function signature was a lie. A lot of signatures for builtin functions haven't been updated to use newer typing features like nullable types or (in PHP8) union types yet. Give it time.<|eor|><|sor|>The big problem is the signatures in the documentation are an ad-hoc thing that predates the actual addition of type declarations, and they don't work quite the same. Eventually PHP will probably move to using real type declarations on internal functions, or something that at least behaves the same, but it's not there yet AFAIK.<|eor|><|eoss|><|endoftext|>
5
lolphp
shaql
bgtmfv
<|sols|><|sot|>"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "<|eot|><|sol|>https://php.net/manual/en/function.hash-equals.php<|eol|><|eols|><|endoftext|>
27
lolphp
steamruler
elniyni
<|sols|><|sot|>"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "<|eot|><|sol|>https://php.net/manual/en/function.hash-equals.php<|eol|><|sor|>Not really lolphp, there's no feasible way as far as I'm aware to do a timing attack safe comparison of objects of different sizes, without padding *both* inputs to an arbitrary size, which might still produce a timing attack, because it's hard to make a timing-safe comparison function. (EDIT: [It's near impossible](https://security.stackexchange.com/questions/49849/timing-safe-string-comparison-avoiding-length-leak)) If you pad the smaller string to the longer string, you have a timing attack since that takes a different amount of time depending on the size of the smaller string compared to the longer string. If you do a timing attack safe comparison between the strings, then stop once one runs out, you have a timing attack since, again, time to execute depends on the difference in size between the two strings. As the name suggests, `hash_equals` are for comparing hashes, and hashes that could meaningfully be compared will be the same length already.<|eor|><|eols|><|endoftext|>
25
lolphp
dotancohen
elnqre3
<|sols|><|sot|>"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "<|eot|><|sol|>https://php.net/manual/en/function.hash-equals.php<|eol|><|sor|>Not really lolphp, there's no feasible way as far as I'm aware to do a timing attack safe comparison of objects of different sizes, without padding *both* inputs to an arbitrary size, which might still produce a timing attack, because it's hard to make a timing-safe comparison function. (EDIT: [It's near impossible](https://security.stackexchange.com/questions/49849/timing-safe-string-comparison-avoiding-length-leak)) If you pad the smaller string to the longer string, you have a timing attack since that takes a different amount of time depending on the size of the smaller string compared to the longer string. If you do a timing attack safe comparison between the strings, then stop once one runs out, you have a timing attack since, again, time to execute depends on the difference in size between the two strings. As the name suggests, `hash_equals` are for comparing hashes, and hashes that could meaningfully be compared will be the same length already.<|eor|><|sor|>The solution provided by Markus P. N. in the comments seems to be the proper way to check non-equal-length strings in a fashion resistant to timing attack. If the strings are unequal length, then perform the full comparison on the known sting against the known string itself, but return FALSE anyway.<|eor|><|eols|><|endoftext|>
11
lolphp
SirClueless
eloodm6
<|sols|><|sot|>"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "<|eot|><|sol|>https://php.net/manual/en/function.hash-equals.php<|eol|><|sor|>Not really lolphp, there's no feasible way as far as I'm aware to do a timing attack safe comparison of objects of different sizes, without padding *both* inputs to an arbitrary size, which might still produce a timing attack, because it's hard to make a timing-safe comparison function. (EDIT: [It's near impossible](https://security.stackexchange.com/questions/49849/timing-safe-string-comparison-avoiding-length-leak)) If you pad the smaller string to the longer string, you have a timing attack since that takes a different amount of time depending on the size of the smaller string compared to the longer string. If you do a timing attack safe comparison between the strings, then stop once one runs out, you have a timing attack since, again, time to execute depends on the difference in size between the two strings. As the name suggests, `hash_equals` are for comparing hashes, and hashes that could meaningfully be compared will be the same length already.<|eor|><|sor|>The solution provided by Markus P. N. in the comments seems to be the proper way to check non-equal-length strings in a fashion resistant to timing attack. If the strings are unequal length, then perform the full comparison on the known sting against the known string itself, but return FALSE anyway.<|eor|><|sor|>The solution provided by Markus P. N. computes strlen($known_string), which depends on the length of $known_string. Then, if the two lengths are not equal, it never accesses $user_string when computing the equality which is likely to cause additional timing differences. Also it uses this bizarre logic at one point, which I don't understand: if (is_string($user_string) !== true) { ... $user_string_len = strlen($user_string); I think it was a misguided attempt to have both of these branches take the same amount of time, but strlen() presumably is just gonna bail immediately on non-strings so it seems pointless. Ultimately I think it's entirely reasonable that hash_equals() is only timing-resistant for equal length strings, and does not consider the length of $known_string to be secret information.<|eor|><|eols|><|endoftext|>
8
lolphp
kokx
elo8z0f
<|sols|><|sot|>"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "<|eot|><|sol|>https://php.net/manual/en/function.hash-equals.php<|eol|><|sor|>Not really lolphp, there's no feasible way as far as I'm aware to do a timing attack safe comparison of objects of different sizes, without padding *both* inputs to an arbitrary size, which might still produce a timing attack, because it's hard to make a timing-safe comparison function. (EDIT: [It's near impossible](https://security.stackexchange.com/questions/49849/timing-safe-string-comparison-avoiding-length-leak)) If you pad the smaller string to the longer string, you have a timing attack since that takes a different amount of time depending on the size of the smaller string compared to the longer string. If you do a timing attack safe comparison between the strings, then stop once one runs out, you have a timing attack since, again, time to execute depends on the difference in size between the two strings. As the name suggests, `hash_equals` are for comparing hashes, and hashes that could meaningfully be compared will be the same length already.<|eor|><|soopr|>Your 'bad' examples are still much better than instantly returning FALSE, as the difference in time would be much lower. > padding both inputs to an arbitrary size, which might still produce a timing attack, because it's hard to make a timing-safe comparison function. But not impossible. Instead of risking a process of padding, which may or may not be vulnerable to another timing attack, you could just iterate the strings in a loop until the arbitraty 'size' is reached, performing the same operations as if the strings didn't end 'early'.<|eoopr|><|sor|>Actually they are all worse. This doesn't give any information about the target string length. But any other scheme will. Your scheme for example is easily binary searchable for the length. It's clear that you simply should not pass strings of non-equal length into the function. The only thing that is wrong, is that it doesn't give an error when you do, so programmers simply won't.<|eor|><|eols|><|endoftext|>
8
lolphp
Idontremember99
elo6ltu
<|sols|><|sot|>"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "<|eot|><|sol|>https://php.net/manual/en/function.hash-equals.php<|eol|><|sor|>"It is important to provide the user-supplied string as the second parameter, rather than the first." Can someone explain why this is important?<|eor|><|eols|><|endoftext|>
6
lolphp
nikic
elqi3cc
<|sols|><|sot|>"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "<|eot|><|sol|>https://php.net/manual/en/function.hash-equals.php<|eol|><|sor|>To be fair: timing safe comparison tends to assume that the lengths of the strings is known in the first place and if they are different, they will obviously be non-equal.<|eor|><|sor|>That's the problem. By providing strings of differing lengths, the attacker can determine the length of the known string by the amount of time until the function returns.<|eor|><|sor|>length is not the secret you want to protect<|eor|><|sor|>Length is not _the_ secret, but it is _a_ secret. As an attacker, I can narrow my search space down by an order of magnitude if I know the length of the secret string, assuming that I'm rolling up. If I'm brute forcing by random, then it will narrow my search space by many orders of magnitude.<|eor|><|sor|>No, it's not even *a* secret. The length of the compared hash is part of the cryptographic construction, which is always considered to be known to attacker. The construction must be cryptographically secure under that assumption, otherwise it's just security by obscurity.<|eor|><|eols|><|endoftext|>
6
lolphp
F-J-W
elno8wu
<|sols|><|sot|>"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "<|eot|><|sol|>https://php.net/manual/en/function.hash-equals.php<|eol|><|sor|>To be fair: timing safe comparison tends to assume that the lengths of the strings is known in the first place and if they are different, they will obviously be non-equal.<|eor|><|eols|><|endoftext|>
5
lolphp
weirdasianfaces
eml4pbg
<|sols|><|sot|>"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "<|eot|><|sol|>https://php.net/manual/en/function.hash-equals.php<|eol|><|sor|>To be fair: timing safe comparison tends to assume that the lengths of the strings is known in the first place and if they are different, they will obviously be non-equal.<|eor|><|sor|>That's the problem. By providing strings of differing lengths, the attacker can determine the length of the known string by the amount of time until the function returns.<|eor|><|sor|>length is not the secret you want to protect<|eor|><|sor|>Length is not _the_ secret, but it is _a_ secret. As an attacker, I can narrow my search space down by an order of magnitude if I know the length of the secret string, assuming that I'm rolling up. If I'm brute forcing by random, then it will narrow my search space by many orders of magnitude.<|eor|><|sor|>No, it's not even *a* secret. The length of the compared hash is part of the cryptographic construction, which is always considered to be known to attacker. The construction must be cryptographically secure under that assumption, otherwise it's just security by obscurity.<|eor|><|sor|>I understand what you are getting at, but not all PHP code is open source. The hashes in use at foo.com are not necessarily known. And in any case, despite the function's name, it might be comparing strings other than hashes (which is the whole point of this thread, i.e. unequal length of known/user strings).<|eor|><|sor|>If your security is dependent on someone not knowing the hash algorithm or the digest size, that probably means you're doing something really really wrong. This core issue isn't even something PHP is only an offender of. .NET Core does an early return if the digest size is different: https://github.com/dotnet/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/CryptographicOperations.cs#L32 ring, a crypto library for rust does as well: https://github.com/briansmith/ring/blob/dd5f7fec815daf28e67bb5738166eb92dfe17ce0/src/constant_time.rs#L24-L27 Go does as well: https://golang.org/src/crypto/subtle/constant_time.go?s=505:546#L2 OpenSSL makes the assumption that they're the same length. There's enough evidence here to say that *you* are the one doing something wrong if you don't want this behavior.<|eor|><|eols|><|endoftext|>
5
lolphp
tdammers
3u8ccs
<|sols|><|sot|>If you can't hack my site, that proves PHP is secure.<|eot|><|sol|>https://www.reddit.com/r/programming/comments/3u85cd/dont_use_the_owasp_phpsec_crypto_library/<|eol|><|eols|><|endoftext|>
23
lolphp
WrasslorMonkey
cxdkety
<|sols|><|sot|>If you can't hack my site, that proves PHP is secure.<|eot|><|sol|>https://www.reddit.com/r/programming/comments/3u85cd/dont_use_the_owasp_phpsec_crypto_library/<|eol|><|sor|>> Kerckhoff's principle applies to cryptography, not application security. Fucking. Gold. Edit: Quote from here: https://github.com/OWASP/phpsec/issues/108 which is a really fun read.<|eor|><|eols|><|endoftext|>
12
lolphp
ajmarks
cxdeo2s
<|sols|><|sot|>If you can't hack my site, that proves PHP is secure.<|eot|><|sol|>https://www.reddit.com/r/programming/comments/3u85cd/dont_use_the_owasp_phpsec_crypto_library/<|eol|><|sor|>what are your trying to link to? I just get the full comments on another reddit thread, the connection to your title is not obvious.<|eor|><|sor|>Probably https://www.reddit.com/r/programming/comments/3u85cd/dont_use_the_owasp_phpsec_crypto_library/cxco9rk<|eor|><|eols|><|endoftext|>
7
lolphp
sarciszewski
cxfnkiz
<|sols|><|sot|>If you can't hack my site, that proves PHP is secure.<|eot|><|sol|>https://www.reddit.com/r/programming/comments/3u85cd/dont_use_the_owasp_phpsec_crypto_library/<|eol|><|sor|>what are your trying to link to? I just get the full comments on another reddit thread, the connection to your title is not obvious.<|eor|><|soopr|>The interesting part, 'The guy running around saying "hack my website it runs PHP"' as someone put it, has been downvoted into oblivion by now. The gist of it was "No, PHP isn't a security problem, look here, my website runs on PHP, if you can't hack it that proves PHP is secure". Which is of course utter nonsense.<|eoopr|><|sor|>There are people who have told me, "PHP and security? Isn't that an oxymoron?" and [other similar sentiments](https://twitter.com/MalwareJake/status/506488937096183808). My usual response is, "Okay, if PHP is inherently insecure, hack this website. If you can't, admit that you're wrong." It isn't meant to be a standalone argument, it's a "put up or shut up" challenge. The context matters a lot. Evaluating it as a standalone argument is, of course, going to seem silly. If paragonie.com is insecure *because* (and *only* because) it runs PHP, then that gives someone a very easy way to prove their point. But if PHP *can be* secure, then claiming that "It runs PHP? It must be insecure!" is wrong.<|eor|><|eols|><|endoftext|>
6
lolphp
tdammers
cxfx6c3
<|sols|><|sot|>If you can't hack my site, that proves PHP is secure.<|eot|><|sol|>https://www.reddit.com/r/programming/comments/3u85cd/dont_use_the_owasp_phpsec_crypto_library/<|eol|><|sor|>> Kerckhoff's principle applies to cryptography, not application security. Fucking. Gold. Edit: Quote from here: https://github.com/OWASP/phpsec/issues/108 which is a really fun read.<|eor|><|soopr|>For some values of "fun". What is it with PHP folks to act butt-hurt rather than genuinely concerned when someone points out a legit security flaw in their stuff?<|eoopr|><|sor|>I don't know, this is atypical of my usual experience with reporting a legit security flaw in the PHP community. 95% of the time, the supplier's response is tantamount to, "Oh shit, thanks for letting me know, I'll try to fix it ASAP!" Of the remaining 5%: 90% have been, "Sorry, I have no idea what this even is, can you walk me through it? Or just send a PR that we'll merge because this is way over our heads?" and then the remaining 10% (or 0.5% total) act like AbiusX or [Daniel Kerr](https://github.com/opencart/opencart/pull/1594).<|eor|><|soopr|>My experience differs. Not my direct problem anymore, but this is one of the reasons why I like to advise anyone against PHP in general.<|eoopr|><|sor|>If you'd prefer some citations, I can send you a PM with a long list of Github issues. :)<|eor|><|soopr|>Oh, I believe you alright. It's just different from my own experience.<|eoopr|><|eols|><|endoftext|>
6
lolphp
sarciszewski
cxfnmz3
<|sols|><|sot|>If you can't hack my site, that proves PHP is secure.<|eot|><|sol|>https://www.reddit.com/r/programming/comments/3u85cd/dont_use_the_owasp_phpsec_crypto_library/<|eol|><|sor|>> Kerckhoff's principle applies to cryptography, not application security. Fucking. Gold. Edit: Quote from here: https://github.com/OWASP/phpsec/issues/108 which is a really fun read.<|eor|><|soopr|>For some values of "fun". What is it with PHP folks to act butt-hurt rather than genuinely concerned when someone points out a legit security flaw in their stuff?<|eoopr|><|sor|>I don't know, this is atypical of my usual experience with reporting a legit security flaw in the PHP community. 95% of the time, the supplier's response is tantamount to, "Oh shit, thanks for letting me know, I'll try to fix it ASAP!" Of the remaining 5%: 90% have been, "Sorry, I have no idea what this even is, can you walk me through it? Or just send a PR that we'll merge because this is way over our heads?" and then the remaining 10% (or 0.5% total) act like AbiusX or [Daniel Kerr](https://github.com/opencart/opencart/pull/1594).<|eor|><|eols|><|endoftext|>
5
lolphp
DoubleNabla
2g531u
<|soss|><|sot|>The Tales of the Magic Mimicry Variable or: $x !== $x<|eot|><|sost|>So, I guess everyone here knows what happens when you use an undefined variable in PHP. php> echo $foo." bar"; PHP Notice: Undefined variable: foo in php shell code on line 1 bar Yeah... it inserts an empty string and emits a _notice_. Barewords (a.k.a. undefined constants) are even better, PHP will just use __the name of the constant as a string__. php > echo foo." bar"; PHP Notice: Use of undefined constant foo - assumed 'foo' in php shell code on line 1 foo bar Let that sink in for a while. I'd say that's insane enough as is, and opens up a lot of potential for both typos and more malicious actions. But that's not it. PHP also allows Unicode (apparently any codepoint which isn't a reserved character or an ASCII control code) to appear in constant and variable names: php > $ = "hi!"; php > echo $; hi! The combination of these two misfeatures allows for some truly diabolical backdoors (as well as inexplicable bugs in the fashion of `2+2 == 2`). Essentially, you can replace variables with undefined (or different) ones which look exactly the same, and all you get is a notice. This can basically be done in two ways: 1. [Homograph attacks](http://en.wikipedia.org/wiki/IDN_homograph_attack): e.g. replacing a latin `a` with a cyrillic ``: $path = "/var/www/foo"; echo $pth."/user/supplied/path"; // prints /user/supplied/path, and emits a notice Another interesting idea is using the [alternative dollar signs](https://en.wikipedia.org/wiki/Dollar_sign#Encoding) in place of the normal `$` variable prefix suddenly, you have an undefined constant that looks like a variable, but will evaluate to a string containing its name... 2. Inserting invisible or almost-invisible characters. The worst of those is probably `U+2060 word joiner`, which is completely invisible, even in most editors which show whitespace. // let's write a secure random number generator $rnd = openssl_random_pseudo_bytes(100); // most likely secure $today = date('c'); // extra entropy can't hurt! $super_secure_rnd = hash("sha512", $rnd.$today); // oops, that's actually $r\u2060nd, which is undefined, // i.e. NULL, and the result depends only on the current time... Both the code and the results still _look_ okay at a cursory glance. Oh, and as I mentioned `hash()`... that's another one of those fail-never-thus-double-deadly functions (I'm sure this has been mentioned here previously): php > var_dump(hash("lolphp", "foo")); PHP Warning: hash(): Unknown hashing algorithm: lolphp in php shell code on line 1 bool(false) Figuring out what the highly secure `sh512` with a cyrillic `` would do is left as an exercise for the reader. But hey, at least it's not a notice. Bonus points in the code-review-dodging discipline are awarded to 2. given that I'd guess most diff tools will either not show this at all, or make it look like an innocent whitespace or linebreak style change. Text-direction marks and such would most likely work as well, and certain diacritics might also be nice, especially if your IDE/console font can't display them. I haven't tried invalid UTF-8 sequences yet I don't think I even want to know. However, I've noticed that the syntax highlighters in some editors (e.g. vim, as well as 3v4l.org) don't recognize _any_ non-ascii variable names. Sometimes, two wrongs do make a right. The safest thing to do would of course be to permit non-ASCII characters only in strings and comments. Or you could put some thought into it and do it properly, i.e. exclude non-printable characters: Python 3.4.1 (default, May 19 2014, 17:23:49) >>> = "hi!" >>> print() hi! >>> boobytrapped = "haxxor" File "<stdin>", line 1 boobytrapped = "haxxor" ^ SyntaxError: invalid character in identifier (I didn't test if it does unicode normalization, but it's Python, it would just throw a NameError otherwise.) In short, these unicode identifiers look like a typical PHP feature. Someone else has it, we need it too! (But don't you dare look at how they did it, or you might risk doing it properly.) Side effects? Unintended consequences? Unforseeable interactions with other... specifics... of our language and interpreter? Fuck that noise. I can excuse falling victim to Unicode traps to some degree, but why the fuck would anyone think simply ignoring the use of undefined variables, and doing something completely insane for undeclared constants, could possibly be a good idea? Granted, you still get a notice, but a) who reads those and b) as part of a backdoor, you could certainly hide an innocent `error_reporting` call somewhere (`0xF7` "make sure we catch all errors!") [Here's some working code.](http://3v4l.org/0uqCf) TL;DR: `var_dump($foo === $fo); // bool(false)` \*mic drop\* <|eost|><|eoss|><|endoftext|>
25
lolphp
DoubleNabla
ckfrfh0
<|soss|><|sot|>The Tales of the Magic Mimicry Variable or: $x !== $x<|eot|><|sost|>So, I guess everyone here knows what happens when you use an undefined variable in PHP. php> echo $foo." bar"; PHP Notice: Undefined variable: foo in php shell code on line 1 bar Yeah... it inserts an empty string and emits a _notice_. Barewords (a.k.a. undefined constants) are even better, PHP will just use __the name of the constant as a string__. php > echo foo." bar"; PHP Notice: Use of undefined constant foo - assumed 'foo' in php shell code on line 1 foo bar Let that sink in for a while. I'd say that's insane enough as is, and opens up a lot of potential for both typos and more malicious actions. But that's not it. PHP also allows Unicode (apparently any codepoint which isn't a reserved character or an ASCII control code) to appear in constant and variable names: php > $ = "hi!"; php > echo $; hi! The combination of these two misfeatures allows for some truly diabolical backdoors (as well as inexplicable bugs in the fashion of `2+2 == 2`). Essentially, you can replace variables with undefined (or different) ones which look exactly the same, and all you get is a notice. This can basically be done in two ways: 1. [Homograph attacks](http://en.wikipedia.org/wiki/IDN_homograph_attack): e.g. replacing a latin `a` with a cyrillic ``: $path = "/var/www/foo"; echo $pth."/user/supplied/path"; // prints /user/supplied/path, and emits a notice Another interesting idea is using the [alternative dollar signs](https://en.wikipedia.org/wiki/Dollar_sign#Encoding) in place of the normal `$` variable prefix suddenly, you have an undefined constant that looks like a variable, but will evaluate to a string containing its name... 2. Inserting invisible or almost-invisible characters. The worst of those is probably `U+2060 word joiner`, which is completely invisible, even in most editors which show whitespace. // let's write a secure random number generator $rnd = openssl_random_pseudo_bytes(100); // most likely secure $today = date('c'); // extra entropy can't hurt! $super_secure_rnd = hash("sha512", $rnd.$today); // oops, that's actually $r\u2060nd, which is undefined, // i.e. NULL, and the result depends only on the current time... Both the code and the results still _look_ okay at a cursory glance. Oh, and as I mentioned `hash()`... that's another one of those fail-never-thus-double-deadly functions (I'm sure this has been mentioned here previously): php > var_dump(hash("lolphp", "foo")); PHP Warning: hash(): Unknown hashing algorithm: lolphp in php shell code on line 1 bool(false) Figuring out what the highly secure `sh512` with a cyrillic `` would do is left as an exercise for the reader. But hey, at least it's not a notice. Bonus points in the code-review-dodging discipline are awarded to 2. given that I'd guess most diff tools will either not show this at all, or make it look like an innocent whitespace or linebreak style change. Text-direction marks and such would most likely work as well, and certain diacritics might also be nice, especially if your IDE/console font can't display them. I haven't tried invalid UTF-8 sequences yet I don't think I even want to know. However, I've noticed that the syntax highlighters in some editors (e.g. vim, as well as 3v4l.org) don't recognize _any_ non-ascii variable names. Sometimes, two wrongs do make a right. The safest thing to do would of course be to permit non-ASCII characters only in strings and comments. Or you could put some thought into it and do it properly, i.e. exclude non-printable characters: Python 3.4.1 (default, May 19 2014, 17:23:49) >>> = "hi!" >>> print() hi! >>> boobytrapped = "haxxor" File "<stdin>", line 1 boobytrapped = "haxxor" ^ SyntaxError: invalid character in identifier (I didn't test if it does unicode normalization, but it's Python, it would just throw a NameError otherwise.) In short, these unicode identifiers look like a typical PHP feature. Someone else has it, we need it too! (But don't you dare look at how they did it, or you might risk doing it properly.) Side effects? Unintended consequences? Unforseeable interactions with other... specifics... of our language and interpreter? Fuck that noise. I can excuse falling victim to Unicode traps to some degree, but why the fuck would anyone think simply ignoring the use of undefined variables, and doing something completely insane for undeclared constants, could possibly be a good idea? Granted, you still get a notice, but a) who reads those and b) as part of a backdoor, you could certainly hide an innocent `error_reporting` call somewhere (`0xF7` "make sure we catch all errors!") [Here's some working code.](http://3v4l.org/0uqCf) TL;DR: `var_dump($foo === $fo); // bool(false)` \*mic drop\* <|eost|><|sor|>The "undefined constant evaluates to its own name" is probably a naive attempt at copying the behavior of many shells, where barewords *are* strings, and quotes around them are only required if they contain characters that would end the bareword.<|eor|><|soopr|>Yes, but shells don't have the constants that PHP has. `echo HOME` will print `HOME`, but you can't declare a constant called `HOME` anyway. There's little room for mistakes, and if you mistype a variable name, it's just empty (not ideal either, admittedly). Compare to PHP: define('PRODUCTION', 1); if(PRODUCKTION == 0) enable_default_passwords; // undeclared constant, that's a string, equals 0, boom! Same story _again_: PHP looks at something someone else does, copies it and completely fucks it up in some way.<|eoopr|><|eoss|><|endoftext|>
8
lolphp
masklinn
clhgq6k
<|soss|><|sot|>The Tales of the Magic Mimicry Variable or: $x !== $x<|eot|><|sost|>So, I guess everyone here knows what happens when you use an undefined variable in PHP. php> echo $foo." bar"; PHP Notice: Undefined variable: foo in php shell code on line 1 bar Yeah... it inserts an empty string and emits a _notice_. Barewords (a.k.a. undefined constants) are even better, PHP will just use __the name of the constant as a string__. php > echo foo." bar"; PHP Notice: Use of undefined constant foo - assumed 'foo' in php shell code on line 1 foo bar Let that sink in for a while. I'd say that's insane enough as is, and opens up a lot of potential for both typos and more malicious actions. But that's not it. PHP also allows Unicode (apparently any codepoint which isn't a reserved character or an ASCII control code) to appear in constant and variable names: php > $ = "hi!"; php > echo $; hi! The combination of these two misfeatures allows for some truly diabolical backdoors (as well as inexplicable bugs in the fashion of `2+2 == 2`). Essentially, you can replace variables with undefined (or different) ones which look exactly the same, and all you get is a notice. This can basically be done in two ways: 1. [Homograph attacks](http://en.wikipedia.org/wiki/IDN_homograph_attack): e.g. replacing a latin `a` with a cyrillic ``: $path = "/var/www/foo"; echo $pth."/user/supplied/path"; // prints /user/supplied/path, and emits a notice Another interesting idea is using the [alternative dollar signs](https://en.wikipedia.org/wiki/Dollar_sign#Encoding) in place of the normal `$` variable prefix suddenly, you have an undefined constant that looks like a variable, but will evaluate to a string containing its name... 2. Inserting invisible or almost-invisible characters. The worst of those is probably `U+2060 word joiner`, which is completely invisible, even in most editors which show whitespace. // let's write a secure random number generator $rnd = openssl_random_pseudo_bytes(100); // most likely secure $today = date('c'); // extra entropy can't hurt! $super_secure_rnd = hash("sha512", $rnd.$today); // oops, that's actually $r\u2060nd, which is undefined, // i.e. NULL, and the result depends only on the current time... Both the code and the results still _look_ okay at a cursory glance. Oh, and as I mentioned `hash()`... that's another one of those fail-never-thus-double-deadly functions (I'm sure this has been mentioned here previously): php > var_dump(hash("lolphp", "foo")); PHP Warning: hash(): Unknown hashing algorithm: lolphp in php shell code on line 1 bool(false) Figuring out what the highly secure `sh512` with a cyrillic `` would do is left as an exercise for the reader. But hey, at least it's not a notice. Bonus points in the code-review-dodging discipline are awarded to 2. given that I'd guess most diff tools will either not show this at all, or make it look like an innocent whitespace or linebreak style change. Text-direction marks and such would most likely work as well, and certain diacritics might also be nice, especially if your IDE/console font can't display them. I haven't tried invalid UTF-8 sequences yet I don't think I even want to know. However, I've noticed that the syntax highlighters in some editors (e.g. vim, as well as 3v4l.org) don't recognize _any_ non-ascii variable names. Sometimes, two wrongs do make a right. The safest thing to do would of course be to permit non-ASCII characters only in strings and comments. Or you could put some thought into it and do it properly, i.e. exclude non-printable characters: Python 3.4.1 (default, May 19 2014, 17:23:49) >>> = "hi!" >>> print() hi! >>> boobytrapped = "haxxor" File "<stdin>", line 1 boobytrapped = "haxxor" ^ SyntaxError: invalid character in identifier (I didn't test if it does unicode normalization, but it's Python, it would just throw a NameError otherwise.) In short, these unicode identifiers look like a typical PHP feature. Someone else has it, we need it too! (But don't you dare look at how they did it, or you might risk doing it properly.) Side effects? Unintended consequences? Unforseeable interactions with other... specifics... of our language and interpreter? Fuck that noise. I can excuse falling victim to Unicode traps to some degree, but why the fuck would anyone think simply ignoring the use of undefined variables, and doing something completely insane for undeclared constants, could possibly be a good idea? Granted, you still get a notice, but a) who reads those and b) as part of a backdoor, you could certainly hide an innocent `error_reporting` call somewhere (`0xF7` "make sure we catch all errors!") [Here's some working code.](http://3v4l.org/0uqCf) TL;DR: `var_dump($foo === $fo); // bool(false)` \*mic drop\* <|eost|><|sor|>> exclude non-printable characters A fairly common solution is to only permit Unicode "letter" and "digit" charaters (extending the usual `/[A-Za-z_][A-Za-z0-9_]*/` identifiers with the corresponding Unicode sets). At least JavaScript (ES) and Haskell do this.<|eor|><|sor|>There's even better: two of the possible properties on a codepoint are `ID_Start` and `ID_Continue` defined in tr31 which > describes specifications for recommended defaults for the use of Unicode in the definitions of identifiers and in pattern-based syntax. `ID_Start` is a valid first codepoint of an identifier, and `ID_Continue` is a valid continuation codepoint of an identifier. Now TR31 is not ideal (e.g. it defines `_` as `ID_Continue` but not `ID_Start`), but it provides a good start and specifially allows extension if desired or necessary: http://www.unicode.org/reports/tr31/#Specific_Character_Adjustments.<|eor|><|eoss|><|endoftext|>
6
lolphp
tdammers
ckfp7v2
<|soss|><|sot|>The Tales of the Magic Mimicry Variable or: $x !== $x<|eot|><|sost|>So, I guess everyone here knows what happens when you use an undefined variable in PHP. php> echo $foo." bar"; PHP Notice: Undefined variable: foo in php shell code on line 1 bar Yeah... it inserts an empty string and emits a _notice_. Barewords (a.k.a. undefined constants) are even better, PHP will just use __the name of the constant as a string__. php > echo foo." bar"; PHP Notice: Use of undefined constant foo - assumed 'foo' in php shell code on line 1 foo bar Let that sink in for a while. I'd say that's insane enough as is, and opens up a lot of potential for both typos and more malicious actions. But that's not it. PHP also allows Unicode (apparently any codepoint which isn't a reserved character or an ASCII control code) to appear in constant and variable names: php > $ = "hi!"; php > echo $; hi! The combination of these two misfeatures allows for some truly diabolical backdoors (as well as inexplicable bugs in the fashion of `2+2 == 2`). Essentially, you can replace variables with undefined (or different) ones which look exactly the same, and all you get is a notice. This can basically be done in two ways: 1. [Homograph attacks](http://en.wikipedia.org/wiki/IDN_homograph_attack): e.g. replacing a latin `a` with a cyrillic ``: $path = "/var/www/foo"; echo $pth."/user/supplied/path"; // prints /user/supplied/path, and emits a notice Another interesting idea is using the [alternative dollar signs](https://en.wikipedia.org/wiki/Dollar_sign#Encoding) in place of the normal `$` variable prefix suddenly, you have an undefined constant that looks like a variable, but will evaluate to a string containing its name... 2. Inserting invisible or almost-invisible characters. The worst of those is probably `U+2060 word joiner`, which is completely invisible, even in most editors which show whitespace. // let's write a secure random number generator $rnd = openssl_random_pseudo_bytes(100); // most likely secure $today = date('c'); // extra entropy can't hurt! $super_secure_rnd = hash("sha512", $rnd.$today); // oops, that's actually $r\u2060nd, which is undefined, // i.e. NULL, and the result depends only on the current time... Both the code and the results still _look_ okay at a cursory glance. Oh, and as I mentioned `hash()`... that's another one of those fail-never-thus-double-deadly functions (I'm sure this has been mentioned here previously): php > var_dump(hash("lolphp", "foo")); PHP Warning: hash(): Unknown hashing algorithm: lolphp in php shell code on line 1 bool(false) Figuring out what the highly secure `sh512` with a cyrillic `` would do is left as an exercise for the reader. But hey, at least it's not a notice. Bonus points in the code-review-dodging discipline are awarded to 2. given that I'd guess most diff tools will either not show this at all, or make it look like an innocent whitespace or linebreak style change. Text-direction marks and such would most likely work as well, and certain diacritics might also be nice, especially if your IDE/console font can't display them. I haven't tried invalid UTF-8 sequences yet I don't think I even want to know. However, I've noticed that the syntax highlighters in some editors (e.g. vim, as well as 3v4l.org) don't recognize _any_ non-ascii variable names. Sometimes, two wrongs do make a right. The safest thing to do would of course be to permit non-ASCII characters only in strings and comments. Or you could put some thought into it and do it properly, i.e. exclude non-printable characters: Python 3.4.1 (default, May 19 2014, 17:23:49) >>> = "hi!" >>> print() hi! >>> boobytrapped = "haxxor" File "<stdin>", line 1 boobytrapped = "haxxor" ^ SyntaxError: invalid character in identifier (I didn't test if it does unicode normalization, but it's Python, it would just throw a NameError otherwise.) In short, these unicode identifiers look like a typical PHP feature. Someone else has it, we need it too! (But don't you dare look at how they did it, or you might risk doing it properly.) Side effects? Unintended consequences? Unforseeable interactions with other... specifics... of our language and interpreter? Fuck that noise. I can excuse falling victim to Unicode traps to some degree, but why the fuck would anyone think simply ignoring the use of undefined variables, and doing something completely insane for undeclared constants, could possibly be a good idea? Granted, you still get a notice, but a) who reads those and b) as part of a backdoor, you could certainly hide an innocent `error_reporting` call somewhere (`0xF7` "make sure we catch all errors!") [Here's some working code.](http://3v4l.org/0uqCf) TL;DR: `var_dump($foo === $fo); // bool(false)` \*mic drop\* <|eost|><|sor|>The "undefined constant evaluates to its own name" is probably a naive attempt at copying the behavior of many shells, where barewords *are* strings, and quotes around them are only required if they contain characters that would end the bareword.<|eor|><|eoss|><|endoftext|>
5
lolphp
davvblack
1h8yow
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|eoss|><|endoftext|>
23
lolphp
VeXCe
carzgiq
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>Perhaps they were made with php?<|eor|><|eoss|><|endoftext|>
45
lolphp
Athox
cav94z4
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>To bash/praise PHP anonymously.<|eor|><|sor|>But it's just a style, as other have pointed out, it's super easy to show the names. (Especially for a sub full of web developers)<|eor|><|sor|>Yeah but PHP developers wouldn't know how.<|eor|><|eoss|><|endoftext|>
25
lolphp
Dereleased
cas39qj
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>I always assumed it was either an AA or Witness Protection style joke, withholding our names/identities to protect the innocent, etc. Of course, you can open a JS console and type `$('.author').show()` to get them all back.<|eor|><|eoss|><|endoftext|>
23
lolphp
Dereleased
cauaefp
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>I always assumed it was either an AA or Witness Protection style joke, withholding our names/identities to protect the innocent, etc. Of course, you can open a JS console and type `$('.author').show()` to get them all back.<|eor|><|sor|>Are you a wizard?<|eor|><|sor|>I can't think of any reason why you shouldn't think so.<|eor|><|eoss|><|endoftext|>
12
lolphp
madlee
cas1jt7
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>so your developer friends won't know about your secret disdain for php.<|eor|><|eoss|><|endoftext|>
11
lolphp
Rhomboid
cas3vdu
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>so your developer friends won't know about your secret disdain for php.<|eor|><|soopr|>But you can still see their names in your inbox, so you know they've been stalking you.<|eoopr|><|sor|>or you can open a JS console and type `$('.author').show()` to get them all back.<|eor|><|sor|>Or disable custom subreddit styles in your site preferences, or use RES to do the same thing on a per-subreddit basis.<|eor|><|eoss|><|endoftext|>
8
lolphp
davvblack
cbiij4k
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>Not to mention timestamps...<|eor|><|soopr|>Case in point, this thread has been dead for decades.<|eoopr|><|eoss|><|endoftext|>
7
lolphp
jerenept
cas4mwy
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>so your developer friends won't know about your secret disdain for php.<|eor|><|soopr|>But you can still see their names in your inbox, so you know they've been stalking you.<|eoopr|><|sor|>or you can open a JS console and type `$('.author').show()` to get them all back.<|eor|><|sor|>Or disable custom subreddit styles in your site preferences, or use RES to do the same thing on a per-subreddit basis.<|eor|><|sor|>http://reddit.com/r/lolphp.compact<|eor|><|eoss|><|endoftext|>
7
lolphp
gearvOsh
cas3os5
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>To bash/praise PHP anonymously.<|eor|><|eoss|><|endoftext|>
6
lolphp
jaimeeee
cau2djq
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>I always assumed it was either an AA or Witness Protection style joke, withholding our names/identities to protect the innocent, etc. Of course, you can open a JS console and type `$('.author').show()` to get them all back.<|eor|><|sor|>Are you a wizard?<|eor|><|eoss|><|endoftext|>
5
lolphp
Turtlecupcakes
casbdkt
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>To bash/praise PHP anonymously.<|eor|><|sor|>But it's just a style, as other have pointed out, it's super easy to show the names. (Especially for a sub full of web developers)<|eor|><|eoss|><|endoftext|>
5
lolphp
Dereleased
cas38rs
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>so your developer friends won't know about your secret disdain for php.<|eor|><|soopr|>But you can still see their names in your inbox, so you know they've been stalking you.<|eoopr|><|sor|>or you can open a JS console and type `$('.author').show()` to get them all back.<|eor|><|eoss|><|endoftext|>
5
lolphp
ekolis
cbiitsp
<|soss|><|sot|>[meta] Why do the custom styles on this subreddit obscure usernames?<|eot|><|sost|><|eost|><|sor|>Not to mention timestamps...<|eor|><|soopr|>Case in point, this thread has been dead for decades.<|eoopr|><|sor|>In that case, do you have some SNES games I could borrow?<|eor|><|eoss|><|endoftext|>
5
lolphp
deviantintegral
1gnhyt
<|soss|><|sot|>Unary operators on strings<|eot|><|sost|>Ran into this where a developer was manually applying a patch (ewww) and forgot to remove a minus sign in the middle of an array declaration. Turns out that plus or minus in front of a string casts it to zero. The minus I'm (somewhat) OK with though I can't think of any reason to negate a string. What's awesome is that I can't find documentation for a + operator anywhere! http://www.php.net/manual/en/language.operators.arithmetic.php <?php $a = array( - 'first key' => 'first value', ); var_dump($a); var_dump(+"first key"); var_dump(-"first key"); // php says! array(1) { [0]=> string(11) "first value" } int(0) int(0) <|eost|><|eoss|><|endoftext|>
24
lolphp
midir
cam1qxk
<|soss|><|sot|>Unary operators on strings<|eot|><|sost|>Ran into this where a developer was manually applying a patch (ewww) and forgot to remove a minus sign in the middle of an array declaration. Turns out that plus or minus in front of a string casts it to zero. The minus I'm (somewhat) OK with though I can't think of any reason to negate a string. What's awesome is that I can't find documentation for a + operator anywhere! http://www.php.net/manual/en/language.operators.arithmetic.php <?php $a = array( - 'first key' => 'first value', ); var_dump($a); var_dump(+"first key"); var_dump(-"first key"); // php says! array(1) { [0]=> string(11) "first value" } int(0) int(0) <|eost|><|sor|>>Turns out that plus or minus in front of a string casts it to zero. Actually, it tries to parse it as a decimal or hexadecimal number, then applies the `+` or `-` to the number. A non-number silently becomes 0. The stranger one is ~, which instead of parsing it as a number, takes the one's complement of the string's bit pattern and returns it as a new string (equivalent to doing ~ to each character value individually). It's hard to see where that would be useful but at least it's consistent to have the full set of bitwise operators, as you can also use \^, &, and | between strings in the same way.<|eor|><|eoss|><|endoftext|>
11
lolphp
vytah
camjlms
<|soss|><|sot|>Unary operators on strings<|eot|><|sost|>Ran into this where a developer was manually applying a patch (ewww) and forgot to remove a minus sign in the middle of an array declaration. Turns out that plus or minus in front of a string casts it to zero. The minus I'm (somewhat) OK with though I can't think of any reason to negate a string. What's awesome is that I can't find documentation for a + operator anywhere! http://www.php.net/manual/en/language.operators.arithmetic.php <?php $a = array( - 'first key' => 'first value', ); var_dump($a); var_dump(+"first key"); var_dump(-"first key"); // php says! array(1) { [0]=> string(11) "first value" } int(0) int(0) <|eost|><|sor|>I love the comments on that page: > A very simple yet maybe not obvious use of the modulus (%) operator is to check if an integer is odd or even. [+3] And the useful comments are downvoted there: >It appears floating-point infinity (INF) is not returned from divide by zero (in PHP 5.0.0). Instead a warning is given and Boolean FALSE is returned. I searched the various manuals and did not find relevant explanation, so am adding this. [-1] >not listed here is the absolutely useless unary plus. [-2] >For larger numbers (above PHP_INT_MAX), use fmod() rather than %. [-4] <|eor|><|eoss|><|endoftext|>
9
lolphp
ealf
p9sn4
<|sols|><|sot|>The case of HTTP response splitting protection in PHP<|eot|><|sol|>http://news.php.net/php.internals/57655<|eol|><|eols|><|endoftext|>
24
lolphp
i-am-am-nice-really
jqum3
<|soss|><|sot|>php --syntax-check somefile.php<|eot|><|sost|>Errors parsing somefile.php *thanks. sigh*<|eost|><|eoss|><|endoftext|>
23
lolphp
i-am-am-nice-really
c2eeiqh
<|soss|><|sot|>php --syntax-check somefile.php<|eot|><|sost|>Errors parsing somefile.php *thanks. sigh*<|eost|><|sor|>quicker to type: php -l somefile.php The 'l' is a lower case 'L'.<|eor|><|soopr|>quicker to not bother at all<|eoopr|><|eoss|><|endoftext|>
6
lolphp
Takeoded
rff8j0
<|sols|><|sot|>you can't use FILE_USE_INCLUDE_PATH in strict mode<|eot|><|sol|>https://www.php.net/manual/en/function.file-get-contents<|eol|><|eols|><|endoftext|>
23
lolphp
Takeoded
hoe4l7a
<|sols|><|sot|>you can't use FILE_USE_INCLUDE_PATH in strict mode<|eot|><|sol|>https://www.php.net/manual/en/function.file-get-contents<|eol|><|sor|>Sounds like this constant should be deprecated, unless it serves some other useful purpose that isn't clear here.<|eor|><|soopr|>ideally you could use FILE_USE_INCLUDE_PATH together with LOCK_SH, much like you can with file_put_contents(), i guess that was the original intention, but noooo they made the argument bool instead of flags<|eoopr|><|eols|><|endoftext|>
6
lolphp
chrismsnz
n0qqvt
<|sols|><|sot|>LIBXML_NOENT enables entity substitution<|eot|><|sol|>https://blog.sonarsource.com/wordpress-xxe-security-vulnerability<|eol|><|eols|><|endoftext|>
23
lolphp
JiminP
gw9d3pm
<|sols|><|sot|>LIBXML_NOENT enables entity substitution<|eot|><|sol|>https://blog.sonarsource.com/wordpress-xxe-security-vulnerability<|eol|><|sor|> if (PHP_VERSION_ID < 80000) { // This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is // disabled by default, so this function is no longer needed to protect against XXE attacks. $loader = libxml_disable_entity_loader(true); } $XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', LIBXML_NOENT); > Even though the name might not suggest it, the flag`LIBXML_NOENT`**enables** entity substitution. > Surprisingly, *NOENT* in this case means that no entities will be left in the result, and thus external entities will be fetched and substituted. tl;dr: wordpress devs were bamboozled by a flag name<|eor|><|eols|><|endoftext|>
16
lolphp
Silly-Freak
gwa1qh2
<|sols|><|sot|>LIBXML_NOENT enables entity substitution<|eot|><|sol|>https://blog.sonarsource.com/wordpress-xxe-security-vulnerability<|eol|><|sor|>[https://www.youtube.com/watch?v=i1n5VDUghaY](https://www.youtube.com/watch?v=i1n5VDUghaY)<|eor|><|eols|><|endoftext|>
5
lolphp
bkdotcom
gwbmp6f
<|sols|><|sot|>LIBXML_NOENT enables entity substitution<|eot|><|sol|>https://blog.sonarsource.com/wordpress-xxe-security-vulnerability<|eol|><|sor|> if (PHP_VERSION_ID < 80000) { // This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is // disabled by default, so this function is no longer needed to protect against XXE attacks. $loader = libxml_disable_entity_loader(true); } $XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', LIBXML_NOENT); > Even though the name might not suggest it, the flag`LIBXML_NOENT`**enables** entity substitution. > Surprisingly, *NOENT* in this case means that no entities will be left in the result, and thus external entities will be fetched and substituted. tl;dr: wordpress devs were bamboozled by a flag name<|eor|><|sor|>tl;dr: wordpress devs<|eor|><|eols|><|endoftext|>
5
lolphp
Takeoded
idui3p
<|sols|><|sot|>breaking-to-fix in_array() for PHP8: OK. breaking-to-fix DateTime::ISO8601 for PHP8? no can do (DateTime::ISO8601 is not legal ISO8601)<|eot|><|sol|>https://3v4l.org/B0Jqh<|eol|><|eols|><|endoftext|>
23