subreddit
stringclasses
7 values
author
stringlengths
3
20
id
stringlengths
5
7
content
stringlengths
67
30.4k
score
int64
0
140k
lolphp
SirClueless
f0f4rai
<|sols|><|sot|>PHP is whitespace insensitive, except when it isn't.<|eot|><|sol|>https://i.redd.it/z4uixvzsssm31.png<|eol|><|soopr|>PhpStorm doesn't catch this. Half of the online sandboxes I tested displayed the above behaviour (e.g. [http://phpfiddle.org/](http://phpfiddle.org/)) and the rest threw an error.<|eoopr|><|sor|>Sounds like something that should be reported to PhpStorm. I notice that the PHP syntax highlighter for https://repl.it also thinks that `<?php}` is a valid PHP opening tag when it isn't (though it uses a proper PHP interpreter so when you run it it does the right thing).<|eor|><|eols|><|endoftext|>
11
lolphp
Vinnie420
f0exv65
<|sols|><|sot|>PHP is whitespace insensitive, except when it isn't.<|eot|><|sol|>https://i.redd.it/z4uixvzsssm31.png<|eol|><|sor|>Thats because you are using the wrong syntax for if statements in html When using : <?php if (true): ?> <div>Hello</div> <?php endif ?> <?php if (false): ?> <div>SECRET</div> <?php endif ?> It outputs only the expected div https://www.php.net/manual/en/control-structures.alternative-syntax.php<|eor|><|sor|>Nevermind your syntax is also valid.. TIL :p But the problem is the fifth line: <?php} A space or newline between php and } fixes the problem, i think it is because it sees it as one symbol, and therefore not running the code because there is no php opening tag<|eor|><|eols|><|endoftext|>
7
lolphp
SirClueless
f0gx1ea
<|sols|><|sot|>PHP is whitespace insensitive, except when it isn't.<|eot|><|sol|>https://i.redd.it/z4uixvzsssm31.png<|eol|><|sor|>Whitespace insensitive means that multiple whitespace characters can be collapsed into one. Not that whitespace can be removed entirely. Consider a trivial case like `return foo;`. Replacing that with `returnfoo;` will break in every language. I agree though that the whitespace requirement after `<?php` is somewhat odd.<|eor|><|sor|>I would say "whitespace insensitive" also applies to syntax elements that can be optionally surrounded with whitespace like `}` `;` `=` `()`, etc. The fact that `if($x==1){}` parses the same as `if ( $x == 1 ) { }` is an example of being insensitive to whitespace around most punctuation characters. But of course PHP isn't universally "whitespace insensitive" in this regard: `if ($ x == 1) {}` is a syntax error, for example. The special requirements around the opening `<?php` tag are just one case of this.<|eor|><|sor|>>`if ($ x == 1) {}` is a syntax error, for example. That's equivalent to `int myInt = 1; if(my int == 1) {}` in something like Java or C, though. You obviously can't stick whitespace inside variable names.<|eor|><|sor|>In PHP, `$` is a proper operator, at least in some senses. For example, you can do this: $x = "y"; $y = "Hello world!"; echo $$x; Or this: $hw = "Hello world!"; echo ${"h" . "w"}; It's just that, unlike most of PHP's operators, it's very sensitive to whether it's surrounded by whitespace, because it's baked into the parser.<|eor|><|eols|><|endoftext|>
7
lolphp
khoyo
f0fuc2x
<|sols|><|sot|>PHP is whitespace insensitive, except when it isn't.<|eot|><|sol|>https://i.redd.it/z4uixvzsssm31.png<|eol|><|sor|>Whitespace insensitive means that multiple whitespace characters can be collapsed into one. Not that whitespace can be removed entirely. Consider a trivial case like `return foo;`. Replacing that with `returnfoo;` will break in every language. I agree though that the whitespace requirement after `<?php` is somewhat odd.<|eor|><|sor|>> Replacing that with `returnfoo;` will break in every language. Not in (old) FORTRAN. It used to be completely insensitive, except in strings.<|eor|><|eols|><|endoftext|>
6
lolphp
Vinnie420
f0f2ekj
<|sols|><|sot|>PHP is whitespace insensitive, except when it isn't.<|eot|><|sol|>https://i.redd.it/z4uixvzsssm31.png<|eol|><|sor|>Thats because you are using the wrong syntax for if statements in html When using : <?php if (true): ?> <div>Hello</div> <?php endif ?> <?php if (false): ?> <div>SECRET</div> <?php endif ?> It outputs only the expected div https://www.php.net/manual/en/control-structures.alternative-syntax.php<|eor|><|sor|>Nevermind your syntax is also valid.. TIL :p But the problem is the fifth line: <?php} A space or newline between php and } fixes the problem, i think it is because it sees it as one symbol, and therefore not running the code because there is no php opening tag<|eor|><|sor|>It's as if the title was accurate in the first place.<|eor|><|sor|>True, i misunderstood the first time. Also, whitespace insensitive means that that it ignores multiple whitespaces in a row, there is still a difference between one and none: $a = 5.5 // float 5.5 $b = 5 . 5 // string 55<|eor|><|eols|><|endoftext|>
5
lolphp
MazeChaZer
4fuam3
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|eols|><|endoftext|>
99
lolphp
Genmutant
d2c0y7s
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I actually don't understand what the hell it's doing that results in that. Can someone break it down and explain it slowly?<|eor|><|sor|> TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' (TRUE ? 'CAR' : FALSE) ? 'HORSE' : 'FEET' 'CAR' ? 'HORSE' : 'FEET' 'HORSE' At least I think that's how it works.<|eor|><|eols|><|endoftext|>
43
lolphp
MazeChaZer
d2c2yni
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I actually don't understand what the hell it's doing that results in that. Can someone break it down and explain it slowly?<|eor|><|sor|> TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' (TRUE ? 'CAR' : FALSE) ? 'HORSE' : 'FEET' 'CAR' ? 'HORSE' : 'FEET' 'HORSE' At least I think that's how it works.<|eor|><|sor|>Yep, that's what it's doing. And shit like this is why if I ever start reaching for a nested ternary operation, I just break that shit up into if/else's. Because this readability is utter garbage.<|eor|><|soopr|>In other langugaues like C or Java the ternary operator is right associative, which makes it much more intuitive. TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' TRUE ? 'CAR' : (FALSE ? 'HORSE' : 'FEET') 'CAR' This example in C makes a little more sense: int n = strcmp(number, "one") == 0 ? 1 : strcmp(number, "two") == 0 ? 2 : strcmp(number, "three") == 0 ? 3 : -1; In PHP the ternary operator ist left associative, which makes it broken, just like you say, it becomes completely incomprehensible<|eoopr|><|eols|><|endoftext|>
29
lolphp
b1ackcat
d2c1cam
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I actually don't understand what the hell it's doing that results in that. Can someone break it down and explain it slowly?<|eor|><|sor|> TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' (TRUE ? 'CAR' : FALSE) ? 'HORSE' : 'FEET' 'CAR' ? 'HORSE' : 'FEET' 'HORSE' At least I think that's how it works.<|eor|><|sor|>Yep, that's what it's doing. And shit like this is why if I ever start reaching for a nested ternary operation, I just break that shit up into if/else's. Because this readability is utter garbage.<|eor|><|eols|><|endoftext|>
25
lolphp
barubary
d2czd8t
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I actually don't understand what the hell it's doing that results in that. Can someone break it down and explain it slowly?<|eor|><|sor|> TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' (TRUE ? 'CAR' : FALSE) ? 'HORSE' : 'FEET' 'CAR' ? 'HORSE' : 'FEET' 'HORSE' At least I think that's how it works.<|eor|><|sor|>Yep, that's what it's doing. And shit like this is why if I ever start reaching for a nested ternary operation, I just break that shit up into if/else's. Because this readability is utter garbage.<|eor|><|soopr|>In other langugaues like C or Java the ternary operator is right associative, which makes it much more intuitive. TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' TRUE ? 'CAR' : (FALSE ? 'HORSE' : 'FEET') 'CAR' This example in C makes a little more sense: int n = strcmp(number, "one") == 0 ? 1 : strcmp(number, "two") == 0 ? 2 : strcmp(number, "three") == 0 ? 3 : -1; In PHP the ternary operator ist left associative, which makes it broken, just like you say, it becomes completely incomprehensible<|eoopr|><|sor|>Or you've got Go, where the official statement is something along the lines of > A ternary operator is at best as clear as an if statement, and is never, ever necessary. Therefore, [Go doesn't have it](https://golang.org/doc/faq#Does_Go_have_a_ternary_form). Problem solved.<|eor|><|sor|>"An if statement is at best as clear as a `goto`, and is never, ever necessary. Therefore X doesn't have it." You can apply the same reasoning to argue against parenthesized subexpressions. `(x + y) * z` can be rewritten as `n = x + y; n * z`, just like the example in the Go FAQ. Problem solved!<|eor|><|eols|><|endoftext|>
24
lolphp
EvilTerran
d2c8473
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>The precedence rules in Perl (and, according to a quick test, in Javascript too) make a lot more sense to me, as it's evaluated like true ? 'car' : ( false ? 'horse' : 'feet' ) i.e. left associative for '?', right associative for ':'. If that doesn't make sense to you: just read it from left to right.<|eor|><|sor|>Also C. And literally every other language with the ?: ternary operator. Because that's the only sensible way to do it - it makes `p ? x : q ? y : z` an expression-level if/elseif/else construct, which could actually be useful; while PHP's interpretation would be like writing `if (p ? q : r)`... and *why would you do that?* PHP's way is so stupid and convention-breaking, I figure it probably started out as a bug in PHP's sick parody of a parser (likely caused by the possibility of nesting not even occurring to Rasmus while he was writing the code to parse ternaries, ie the parse tree was effectively picked at random)... and by the time anyone noticed, "muh backwards compatibility" meant it could never be changed, so now it's a "feature".<|eor|><|eols|><|endoftext|>
18
lolphp
greyfade
d2c2xnf
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I actually don't understand what the hell it's doing that results in that. Can someone break it down and explain it slowly?<|eor|><|sor|> TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' (TRUE ? 'CAR' : FALSE) ? 'HORSE' : 'FEET' 'CAR' ? 'HORSE' : 'FEET' 'HORSE' At least I think that's how it works.<|eor|><|sor|>Yep, that's what it's doing. And shit like this is why if I ever start reaching for a nested ternary operation, I just break that shit up into if/else's. Because this readability is utter garbage.<|eor|><|sor|>It's worse because PHP is doing literally the exact opposite that every other language does if it has this operator: PHP treats it as left-associative. C and literally every other language that has it treats it as *right*-associative.<|eor|><|eols|><|endoftext|>
14
lolphp
barubary
d2czo7a
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>Am I the only one not confused by this? The ternary operations evaluate left to right, and non-empty strings are implicitly true. So the path of true -> 'Car' -> 'Horse' makes sense. That being said, I would strangle anyone writing code like this. You shouldn't use strings implicitly as bools, but more importantly you shouldn't string together ternary operations like this. Either way, not really /r/lolphp in my opinion (but then, what else is new).<|eor|><|sor|>> The ternary operations evaluate left to right This is the lolphp. `?:` associates to the right in literally every other language with `?:`, because that's the only interpretation that's actually useful in code. PHP does it differently for no reason, in a way that doesn't make sense, so you get people saying "you shouldn't do that anyway" when it's really just PHP being dumb.<|eor|><|eols|><|endoftext|>
13
lolphp
h0rst_
d2c2txf
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I actually don't understand what the hell it's doing that results in that. Can someone break it down and explain it slowly?<|eor|><|sor|> TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' (TRUE ? 'CAR' : FALSE) ? 'HORSE' : 'FEET' 'CAR' ? 'HORSE' : 'FEET' 'HORSE' At least I think that's how it works.<|eor|><|sor|>Yep, that's what it's doing. And shit like this is why if I ever start reaching for a nested ternary operation, I just break that shit up into if/else's. Because this readability is utter garbage.<|eor|><|sor|> var = cond1 ? val1 : cond2 ? val2 : val3 I think this is pretty readable. The problem here is that PHP interprets it different than any other language I know<|eor|><|eols|><|endoftext|>
13
lolphp
MazeChaZer
d2bzuno
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|soopr|>The related [PHP Sadness](http://www.phpsadness.com/sad/30) article has already been here [a few years ago](https://www.reddit.com/r/lolphp/comments/ywk69/ternary_operator_true_logic_false_file_not_found/)<|eoopr|><|eols|><|endoftext|>
12
lolphp
shvelo
d2c3re0
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>let's add parentheses for clarity (true ? 'car' : false) ? 'horse' : 'feet' (true ? 'car' : false) will evaluate to 'car' 'car' ? 'horse' : 'feet' since non-empty strings are truthy, this will be same as true ? 'horse' : 'feet' so it evaluates to 'horse' Use of more than one ternary operator in the same expression would be really confusing in any language. <|eor|><|eols|><|endoftext|>
10
lolphp
BilgeXA
d2cegyr
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I find it ironic that by posting this you're also beating a dead horse.<|eor|><|eols|><|endoftext|>
9
lolphp
Vakieh
d2cdm4f
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>Nested ternaries is a fireable offence in any decent shop regardless of the language. When syntactic sugar tastes like shit what good is it?<|eor|><|eols|><|endoftext|>
9
lolphp
masklinn
d2elpxx
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I actually don't understand what the hell it's doing that results in that. Can someone break it down and explain it slowly?<|eor|><|sor|> TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' (TRUE ? 'CAR' : FALSE) ? 'HORSE' : 'FEET' 'CAR' ? 'HORSE' : 'FEET' 'HORSE' At least I think that's how it works.<|eor|><|sor|>Yep, that's what it's doing. And shit like this is why if I ever start reaching for a nested ternary operation, I just break that shit up into if/else's. Because this readability is utter garbage.<|eor|><|soopr|>In other langugaues like C or Java the ternary operator is right associative, which makes it much more intuitive. TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' TRUE ? 'CAR' : (FALSE ? 'HORSE' : 'FEET') 'CAR' This example in C makes a little more sense: int n = strcmp(number, "one") == 0 ? 1 : strcmp(number, "two") == 0 ? 2 : strcmp(number, "three") == 0 ? 3 : -1; In PHP the ternary operator ist left associative, which makes it broken, just like you say, it becomes completely incomprehensible<|eoopr|><|sor|>Or you've got Go, where the official statement is something along the lines of > A ternary operator is at best as clear as an if statement, and is never, ever necessary. Therefore, [Go doesn't have it](https://golang.org/doc/faq#Does_Go_have_a_ternary_form). Problem solved.<|eor|><|sor|>Or you've got an expression-based language (like most functional languages) where you don't need the ternary because a regular `if` can have a result and be perfectly unambiguous. Also switch (or whatever it's called in the language)<|eor|><|eols|><|endoftext|>
9
lolphp
kovensky
d2cu5xx
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I actually don't understand what the hell it's doing that results in that. Can someone break it down and explain it slowly?<|eor|><|sor|> TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' (TRUE ? 'CAR' : FALSE) ? 'HORSE' : 'FEET' 'CAR' ? 'HORSE' : 'FEET' 'HORSE' At least I think that's how it works.<|eor|><|sor|>Yep, that's what it's doing. And shit like this is why if I ever start reaching for a nested ternary operation, I just break that shit up into if/else's. Because this readability is utter garbage.<|eor|><|soopr|>In other langugaues like C or Java the ternary operator is right associative, which makes it much more intuitive. TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' TRUE ? 'CAR' : (FALSE ? 'HORSE' : 'FEET') 'CAR' This example in C makes a little more sense: int n = strcmp(number, "one") == 0 ? 1 : strcmp(number, "two") == 0 ? 2 : strcmp(number, "three") == 0 ? 3 : -1; In PHP the ternary operator ist left associative, which makes it broken, just like you say, it becomes completely incomprehensible<|eoopr|><|sor|>Or you've got Go, where the official statement is something along the lines of > A ternary operator is at best as clear as an if statement, and is never, ever necessary. Therefore, [Go doesn't have it](https://golang.org/doc/faq#Does_Go_have_a_ternary_form). Problem solved.<|eor|><|sor|>However, Go has an actually useful switch statement. Unfortunately not an expression, but YMMV.<|eor|><|eols|><|endoftext|>
8
lolphp
bart2019
d2c6vk6
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>The precedence rules in Perl (and, according to a quick test, in Javascript too) make a lot more sense to me, as it's evaluated like true ? 'car' : ( false ? 'horse' : 'feet' ) i.e. left associative for '?', right associative for ':'. If that doesn't make sense to you: just read it from left to right.<|eor|><|eols|><|endoftext|>
7
lolphp
DoctorWaluigiTime
d2d03w7
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I actually don't understand what the hell it's doing that results in that. Can someone break it down and explain it slowly?<|eor|><|sor|> TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' (TRUE ? 'CAR' : FALSE) ? 'HORSE' : 'FEET' 'CAR' ? 'HORSE' : 'FEET' 'HORSE' At least I think that's how it works.<|eor|><|sor|>Yep, that's what it's doing. And shit like this is why if I ever start reaching for a nested ternary operation, I just break that shit up into if/else's. Because this readability is utter garbage.<|eor|><|soopr|>In other langugaues like C or Java the ternary operator is right associative, which makes it much more intuitive. TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' TRUE ? 'CAR' : (FALSE ? 'HORSE' : 'FEET') 'CAR' This example in C makes a little more sense: int n = strcmp(number, "one") == 0 ? 1 : strcmp(number, "two") == 0 ? 2 : strcmp(number, "three") == 0 ? 3 : -1; In PHP the ternary operator ist left associative, which makes it broken, just like you say, it becomes completely incomprehensible<|eoopr|><|sor|>Or you've got Go, where the official statement is something along the lines of > A ternary operator is at best as clear as an if statement, and is never, ever necessary. Therefore, [Go doesn't have it](https://golang.org/doc/faq#Does_Go_have_a_ternary_form). Problem solved.<|eor|><|sor|>Eh, while it's definitely a way to avoid the problem, there's nothing innately wrong with the ternary statement on its own. Much like how Go doesn't have inheritance.<|eor|><|eols|><|endoftext|>
7
lolphp
cparen
d2c95ut
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>The precedence rules in Perl (and, according to a quick test, in Javascript too) make a lot more sense to me, as it's evaluated like true ? 'car' : ( false ? 'horse' : 'feet' ) i.e. left associative for '?', right associative for ':'. If that doesn't make sense to you: just read it from left to right.<|eor|><|sor|>Also C. And literally every other language with the ?: ternary operator. Because that's the only sensible way to do it - it makes `p ? x : q ? y : z` an expression-level if/elseif/else construct, which could actually be useful; while PHP's interpretation would be like writing `if (p ? q : r)`... and *why would you do that?* PHP's way is so stupid and convention-breaking, I figure it probably started out as a bug in PHP's sick parody of a parser (likely caused by the possibility of nesting not even occurring to Rasmus while he was writing the code to parse ternaries, ie the parse tree was effectively picked at random)... and by the time anyone noticed, "muh backwards compatibility" meant it could never be changed, so now it's a "feature".<|eor|><|sor|>> and by the time anyone noticed, "muh backwards compatibility" meant it could never be changed, so now it's a "feature". Your guess is very close to reality. The bug report was posted on lolphp a while back, and it also argued that no one should use the feature anyway, so it's OK if it's broken.<|eor|><|eols|><|endoftext|>
6
lolphp
ReversedGif
d2cavcs
<|sols|><|sot|>The behavior of the ternary operator is sensible and straightforward<|eot|><|sol|>https://i.imgur.com/1zgFd.jpg<|eol|><|sor|>I actually don't understand what the hell it's doing that results in that. Can someone break it down and explain it slowly?<|eor|><|sor|> TRUE ? 'CAR' : FALSE ? 'HORSE' : 'FEET' (TRUE ? 'CAR' : FALSE) ? 'HORSE' : 'FEET' 'CAR' ? 'HORSE' : 'FEET' 'HORSE' At least I think that's how it works.<|eor|><|sor|>Is that not how it should work though? A ternary will typecast to a bool in php. 'CAR' ? 'HORSE' : 'FEET' TRUE ? 'HORSE' : 'FEET' 'HORSE' Do other languages evaluate something like this differently? Serious question.<|eor|><|sor|>It's the associativity that's wrong. Look at the other sibling comments.<|eor|><|eols|><|endoftext|>
6
lolphp
Hauleth
4z5ss3
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|eols|><|endoftext|>
95
lolphp
Hauleth
d6t4fmw
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|eols|><|endoftext|>
28
lolphp
the_alias_of_andrea
d6tdds9
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|sor|>[deleted]<|eor|><|sor|>Not unique to PHP. Most untyped languages do this.<|eor|><|sor|>Few handle weak typing quite as unhelpfully as PHP does. JavaScript and Perl both have more workable approaches.<|eor|><|eols|><|endoftext|>
28
lolphp
MMauro94
d6tkkj7
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>I'm just gonna change *some* code...brb<|eor|><|eols|><|endoftext|>
20
lolphp
masklinn
d6t5dcb
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|sor|>[deleted]<|eor|><|sor|>> Python does the same: No, Python does something completely different. It defines `bool` is an actual subtype of `int`[0] with values specifically equal to `0` and `1`. There is no cast here. [0] because the bool type was only added in Python 2.3 circa 2003 and older code generally used 0 and 1 for those purposes.<|eor|><|eols|><|endoftext|>
18
lolphp
maweki
d6t61fa
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|sor|>[deleted]<|eor|><|sor|>> Python does the same: No, Python does something completely different. It defines `bool` is an actual subtype of `int`[0] with values specifically equal to `0` and `1`. There is no cast here. [0] because the bool type was only added in Python 2.3 circa 2003 and older code generally used 0 and 1 for those purposes.<|eor|><|sor|>Adding to that, in Python specifically only these two equalities hold: `1 == True` and `0 == False`. What specifically doesn't hold is `True == object()` which does indeed hold in php and actually causes the issue because in php an existing object is always `==`-equal to true. While a new object in python is indeed `bool(object())` `True`, the type juggling isn't done automatically.<|eor|><|eols|><|endoftext|>
13
lolphp
masklinn
d6t5ucs
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|sor|>[deleted]<|eor|><|sor|>> Python does the same: No, Python does something completely different. It defines `bool` is an actual subtype of `int`[0] with values specifically equal to `0` and `1`. There is no cast here. [0] because the bool type was only added in Python 2.3 circa 2003 and older code generally used 0 and 1 for those purposes.<|eor|><|sor|>[deleted]<|eor|><|sor|>Hardly, the Python version only works for types specifically defined as equal but not for random arbitrary type, and neither `[True, False]` nor `{'foo': True, 'bar': False }` will reply that they contain everything.<|eor|><|eols|><|endoftext|>
12
lolphp
Hauleth
d6t5vsc
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|sor|>[deleted]<|eor|><|soopr|>It doesn't mean that this is sane behaviour. It only means that Python has some of its insanity also.<|eoopr|><|sor|>[deleted]<|eor|><|soopr|>Hold your horses macho. Dynamic typing isn't problem there. Weak typing is. And in any real work scenario, weak typing will be PITA, it is good for simple scripts, not for whole apps.<|eoopr|><|eols|><|endoftext|>
11
lolphp
Hauleth
d6t6azi
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|sor|>[deleted]<|eor|><|soopr|>It doesn't mean that this is sane behaviour. It only means that Python has some of its insanity also.<|eoopr|><|sor|>[deleted]<|eor|><|soopr|>Hold your horses macho. Dynamic typing isn't problem there. Weak typing is. And in any real work scenario, weak typing will be PITA, it is good for simple scripts, not for whole apps.<|eoopr|><|sor|>[deleted]<|eor|><|soopr|>But Python isn't weak typed. See /r/masklinn answer.<|eoopr|><|eols|><|endoftext|>
9
lolphp
masklinn
d6t5vcp
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|sor|>[deleted]<|eor|><|soopr|>It doesn't mean that this is sane behaviour. It only means that Python has some of its insanity also.<|eoopr|><|sor|>[deleted]<|eor|><|sor|>> Or that both languages make use of dynamic typing. These behaviours are completely orthogonal to dynamic typing, and depending on the type system and protocols/interfaces definitions you could probably define the Python one in some statically typed languages.<|eor|><|eols|><|endoftext|>
7
lolphp
Hauleth
d6tlzhu
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|sor|>[deleted]<|eor|><|sor|>Not unique to PHP. Most untyped languages do this.<|eor|><|soopr|>`s/untyped/weakly typed/`<|eoopr|><|eols|><|endoftext|>
6
lolphp
hylje
d6t6f8w
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|sor|>[deleted]<|eor|><|sor|>> Python does the same: No, Python does something completely different. It defines `bool` is an actual subtype of `int`[0] with values specifically equal to `0` and `1`. There is no cast here. [0] because the bool type was only added in Python 2.3 circa 2003 and older code generally used 0 and 1 for those purposes.<|eor|><|sor|>[deleted]<|eor|><|sor|>In Python it's a code smell if you compare values to `True` or `False`. Everything in the language implements the boolean protocol, so comparisons to literal booleans are useless.<|eor|><|eols|><|endoftext|>
6
lolphp
allthediamonds
d6wp8ne
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|sor|>Not knowing what magical incantations will make PHP behave in a reasonable manner is not a loldeveloper.<|eor|><|eols|><|endoftext|>
5
lolphp
Various_Pickles
d6vlqe1
<|sols|><|sot|>If array contain true and false then it also contain everything else.<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/acac39a42fa6d6592053c972995fbbbd9d8b9e18<|eol|><|sor|>This is why you always use `in_array($a, $b, true)`. Half lolphp half loldeveloper.<|eor|><|soopr|>Half lolphp half lol `==` by default.<|eoopr|><|sor|> Half lolphp half lol == 1; Half lolphp half lol == mysql_no_really_this_time_escape_sql("fucking Johnny Tables"); lolphp_error(); > trolololo PHP error, instead of an exception, written to stderr and the outputted HTML; btw, current HTTP session ID = fe5349d523ab3250, TLS session shared secret = 48a63d1ba4146f<|eor|><|eols|><|endoftext|>
5
lolphp
sarciszewski
3fct2t
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|eols|><|endoftext|>
93
lolphp
manuscelerdei
ctnp6jr
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>> This can be wrapped in an oop wrapper in userland if somebody prefers and exception but would still keep the procedural style as first class citizen. Do PHP programmers think they're operating in the kernel or something? This is all userland. <|eor|><|eols|><|endoftext|>
62
lolphp
Aquatakat
ctns89h
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>> This can be wrapped in an oop wrapper in userland if somebody prefers and exception but would still keep the procedural style as first class citizen. Do PHP programmers think they're operating in the kernel or something? This is all userland. <|eor|><|sor|>Imagine a kernel written in PHP.<|eor|><|sor|>I just had a stroke, thanks.<|eor|><|eols|><|endoftext|>
46
lolphp
Sebbe
ctnqy95
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>> This can be wrapped in an oop wrapper in userland if somebody prefers and exception but would still keep the procedural style as first class citizen. Do PHP programmers think they're operating in the kernel or something? This is all userland. <|eor|><|sor|>Imagine a kernel written in PHP.<|eor|><|eols|><|endoftext|>
45
lolphp
IForgetMyself
ctnufmb
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>[deleted]<|eor|><|sor|>I downvoted you for sheer stupidity, then I saw the footer... Poe's law in action I guess. <|eor|><|eols|><|endoftext|>
27
lolphp
polish_niceguy
ctntazp
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>> This can be wrapped in an oop wrapper in userland if somebody prefers and exception but would still keep the procedural style as first class citizen. Do PHP programmers think they're operating in the kernel or something? This is all userland. <|eor|><|sor|>No, this is only [pure Rasmus bullshit](http://www.brainyquote.com/quotes/quotes/r/rasmuslerd649671.html). Same as keeping the C function names [because someone somewhere would like to use `man`](http://grokbase.com/p/php/php-internals/1533aw03tz/php-dev-consistent-function-names).<|eor|><|eols|><|endoftext|>
26
lolphp
caffeinep0wered
ctnt869
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>> This can be wrapped in an oop wrapper in userland if somebody prefers and exception but would still keep the procedural style as first class citizen. Do PHP programmers think they're operating in the kernel or something? This is all userland. <|eor|><|sor|>Imagine a kernel written in PHP.<|eor|><|sor|>[Imagick::convolveImage\(\)](http://php.net/manual/en/imagick.convolveimage.php) am I doin it rite?<|eor|><|eols|><|endoftext|>
23
lolphp
ThisIsADogHello
ctnwcu3
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>> This can be wrapped in an oop wrapper in userland if somebody prefers and exception but would still keep the procedural style as first class citizen. Do PHP programmers think they're operating in the kernel or something? This is all userland. <|eor|><|sor|>No, this is only [pure Rasmus bullshit](http://www.brainyquote.com/quotes/quotes/r/rasmuslerd649671.html). Same as keeping the C function names [because someone somewhere would like to use `man`](http://grokbase.com/p/php/php-internals/1533aw03tz/php-dev-consistent-function-names).<|eor|><|sor|>Ah yes, let's make a scripting language that's a drop-in replacement for the low level language we're trying to avoid, just in case somebody's looking at the wrong manual. This is a good plan.<|eor|><|eols|><|endoftext|>
23
lolphp
thelordofcheese
ctnwl13
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>> This can be wrapped in an oop wrapper in userland if somebody prefers and exception but would still keep the procedural style as first class citizen. Do PHP programmers think they're operating in the kernel or something? This is all userland. <|eor|><|sor|>No, this is only [pure Rasmus bullshit](http://www.brainyquote.com/quotes/quotes/r/rasmuslerd649671.html). Same as keeping the C function names [because someone somewhere would like to use `man`](http://grokbase.com/p/php/php-internals/1533aw03tz/php-dev-consistent-function-names).<|eor|><|sor|>Ah yes, let's make a scripting language that's a drop-in replacement for the low level language we're trying to avoid, just in case somebody's looking at the wrong manual. This is a good plan.<|eor|><|sor|>brb buying a Astin Martin manual for my VW Bug.<|eor|><|eols|><|endoftext|>
13
lolphp
myaut
ctp5i5s
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>The real lolphp here is that availability of `/dev/urandom` or `/dev/arandom` is checked statically using compile-time directives: https://github.com/php/php-src/blob/master/ext/standard/random.c#L92 So if you install PHP from binary builds, it `random_int` can break because build host has `/dev/arandom` while your host don't. Installing PHP into LXC container could be even worse...<|eor|><|eols|><|endoftext|>
10
lolphp
CornPlanter
ctntoqw
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>[deleted]<|eor|><|sor|>Because here, in planet reality, where we write software that enough people care about to be hit by exploits all the time, we take security seriously.<|eor|><|sor|>Meanwhile on Planet HilariousFuckups we use Brainfuck. But I've heard there's also a Planet PretentiousAmateur, lets ask them what they use...<|eor|><|eols|><|endoftext|>
10
lolphp
amphetamachine
ctnpzny
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>> This can be wrapped in an oop wrapper in userland if somebody prefers and exception but would still keep the procedural style as first class citizen. Do PHP programmers think they're operating in the kernel or something? This is all userland. <|eor|><|sor|>I think they mean consumer code. But yeah, misnomer.<|eor|><|eols|><|endoftext|>
6
lolphp
sarciszewski
ctol2sq
<|sols|><|sot|>Why PHP sucks at security: people arguing against security because it's "consistent" with existing bad practices.<|eot|><|sol|>http://news.php.net/php.internals/87473<|eol|><|sor|>> This can be wrapped in an oop wrapper in userland if somebody prefers and exception but would still keep the procedural style as first class citizen. Do PHP programmers think they're operating in the kernel or something? This is all userland. <|eor|><|sor|>Imagine a kernel written in PHP.<|eor|><|soopr|>I've built some crazy stuff in PHP, myself, but a kernel? This is madness.<|eoopr|><|eols|><|endoftext|>
6
lolphp
Daniel15
2hedsm
<|sols|><|sot|>"The root of the problem is that HHVM implements Memcached::increment/decrement as they are documented, rather than how PHP5 actually behaves"<|eot|><|sol|>https://github.com/facebook/hhvm/issues/3839<|eol|><|eols|><|endoftext|>
93
lolphp
Various_Pickles
ckscgse
<|sols|><|sot|>"The root of the problem is that HHVM implements Memcached::increment/decrement as they are documented, rather than how PHP5 actually behaves"<|eot|><|sol|>https://github.com/facebook/hhvm/issues/3839<|eol|><|sor|>Convert whatever object is causing the issue to a string (completely ignore locale or assume the code will always be executed wherever you are at the moment). Dispatch any errors that are generated during this process by randomly choosing one of the error/exception handling mechanisms in the language, ignoring it, and piping to stderr. Pipe 10GB of /dev/null into a file called php.ini. Repeat for every folder in /etc. You have won at PHP.<|eor|><|eols|><|endoftext|>
14
lolphp
masterwit
ckssk7v
<|sols|><|sot|>"The root of the problem is that HHVM implements Memcached::increment/decrement as they are documented, rather than how PHP5 actually behaves"<|eot|><|sol|>https://github.com/facebook/hhvm/issues/3839<|eol|><|sor|>This subreddit has convinced me to never seriously learn PHP... thank fucking god.<|eor|><|eols|><|endoftext|>
7
lolphp
i-am-am-nice-really
jqn3t
<|sols|><|sot|>5.3.7 Fails unit test, released anyway<|eot|><|sol|>https://bugs.php.net/bug.php?id=55439<|eol|><|eols|><|endoftext|>
94
lolphp
_SynthesizerPatel_
c2eh4f2
<|sols|><|sot|>5.3.7 Fails unit test, released anyway<|eot|><|sol|>https://bugs.php.net/bug.php?id=55439<|eol|><|sor|>Read the headline as [this](http://i.imgur.com/cAvSr.jpg)<|eor|><|eols|><|endoftext|>
12
lolphp
tonygoold
c2eez2e
<|sols|><|sot|>5.3.7 Fails unit test, released anyway<|eot|><|sol|>https://bugs.php.net/bug.php?id=55439<|eol|><|soopr|>Anyway guess who did it : "let's use strlcpy/strlcat instead for these static string copies" - Rasmus I guess that's Lerdorf himself Here's where he broke it : Sun Aug 7 16:10:34 2011 UTC http://svn.php.net/viewvc/php/php-src/trunk/ext/standard/php_crypt_r.c?sortdir=down&r1=313615&r2=314434&sortby=date Here's it being fixed : Fri Aug 19 22:49:18 2011 UTC http://svn.php.net/viewvc/php/php-src/trunk/ext/standard/php_crypt_r.c?sortdir=down&r1=314438&r2=315218&sortby=date <|eoopr|><|sor|>[This](http://svn.php.net/viewvc/php/php-src/trunk/ext/standard/php_crypt_r.c?sortdir=down&r1=314434&r2=314438&sortby=date) is the one where he broke it. For anyone not versed in these C functions and curious about the bug, the difference between `strncat(s1, s2, n)` and `strlcat(s1, s2, n)` is that `strncat` appends up to `n` characters from `s2` to `s1` and null-terminates the result, while `strlcat` limits the total length to `n - 1` and null-terminates the result (unless `n` is 0). So `strlen(strncat(s1, s2, n)) <= strlen(s1) + n`, but `strlen(strlcat(s1, s2, n)) <= n - 1`. `strlcat(password, "$", 1)` will result in a zero-length string no matter what the first two arguments are.<|eor|><|eols|><|endoftext|>
8
lolphp
i-am-am-nice-really
c2ed2qs
<|sols|><|sot|>5.3.7 Fails unit test, released anyway<|eot|><|sol|>https://bugs.php.net/bug.php?id=55439<|eol|><|soopr|>Anyway guess who did it : "let's use strlcpy/strlcat instead for these static string copies" - Rasmus I guess that's Lerdorf himself Here's where he broke it : Sun Aug 7 16:10:34 2011 UTC http://svn.php.net/viewvc/php/php-src/trunk/ext/standard/php_crypt_r.c?sortdir=down&r1=313615&r2=314434&sortby=date Here's it being fixed : Fri Aug 19 22:49:18 2011 UTC http://svn.php.net/viewvc/php/php-src/trunk/ext/standard/php_crypt_r.c?sortdir=down&r1=314438&r2=315218&sortby=date <|eoopr|><|eols|><|endoftext|>
7
lolphp
Takeoded
hj6p07
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|eols|><|endoftext|>
94
lolphp
stfcfanhazz
fwkgao7
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|sor|>Weird. Just when i thought i had the loose comparison type juggling figured out, apparently integer 0 causes literally any string that doesnt start with a numeric character to be equal. Integer 0 is "falsey" in PHP, but a filled string is inherently "truthy" so its hard to wrap your head around this one. My best guess as to what's going on is that PHP is trying to cast the string to integer, which yields a 0 (because its a non-numeric string) so the comparison passes. If the string was "numeric"-ish (begin with integer character(s)) then the result would be different e.g., \`if (0 == '20asdf')\` would return false cause PHP would determine the integer value of that string to be \`20\`. Strong /r/lolphp here for sure.<|eor|><|eols|><|endoftext|>
55
lolphp
marcio0
fwkx9r7
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|sor|>inb4 "it's documented therefore it's correct"<|eor|><|eols|><|endoftext|>
19
lolphp
f0rc3u2
fwkk072
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|sor|>Weird. Just when i thought i had the loose comparison type juggling figured out, apparently integer 0 causes literally any string that doesnt start with a numeric character to be equal. Integer 0 is "falsey" in PHP, but a filled string is inherently "truthy" so its hard to wrap your head around this one. My best guess as to what's going on is that PHP is trying to cast the string to integer, which yields a 0 (because its a non-numeric string) so the comparison passes. If the string was "numeric"-ish (begin with integer character(s)) then the result would be different e.g., \`if (0 == '20asdf')\` would return false cause PHP would determine the integer value of that string to be \`20\`. Strong /r/lolphp here for sure.<|eor|><|sor|>It would definitely make more sense to convert the int to a String and compare it. God sometimes PHP really doesn't make any sense...<|eor|><|eols|><|endoftext|>
18
lolphp
gevrik
fwkvkiv
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|sor|>Weird. Just when i thought i had the loose comparison type juggling figured out, apparently integer 0 causes literally any string that doesnt start with a numeric character to be equal. Integer 0 is "falsey" in PHP, but a filled string is inherently "truthy" so its hard to wrap your head around this one. My best guess as to what's going on is that PHP is trying to cast the string to integer, which yields a 0 (because its a non-numeric string) so the comparison passes. If the string was "numeric"-ish (begin with integer character(s)) then the result would be different e.g., \`if (0 == '20asdf')\` would return false cause PHP would determine the integer value of that string to be \`20\`. Strong /r/lolphp here for sure.<|eor|><|sor|>It would definitely make more sense to convert the int to a String and compare it. God sometimes PHP really doesn't make any sense...<|eor|><|sor|>Until you realise that you can (and should) use strict types.<|eor|><|eols|><|endoftext|>
13
lolphp
Takeoded
fwkfboa
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|soopr|>come to think of it, PHP8 would be a good time to BC-break-fix whatever the fuck that is, wouldn't it? (bet they can't fix it in PHP7)<|eoopr|><|eols|><|endoftext|>
12
lolphp
jmcs
fwl3tyr
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|sor|>...wait, is it somehow reading that string as NaN, and just saying sure, falsey == falsey?<|eor|><|sor|>`(int)"gfsdgsfdgsdf" === 0` because logic is a potato.<|eor|><|eols|><|endoftext|>
11
lolphp
f0rc3u2
fwkyagj
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|sor|>Weird. Just when i thought i had the loose comparison type juggling figured out, apparently integer 0 causes literally any string that doesnt start with a numeric character to be equal. Integer 0 is "falsey" in PHP, but a filled string is inherently "truthy" so its hard to wrap your head around this one. My best guess as to what's going on is that PHP is trying to cast the string to integer, which yields a 0 (because its a non-numeric string) so the comparison passes. If the string was "numeric"-ish (begin with integer character(s)) then the result would be different e.g., \`if (0 == '20asdf')\` would return false cause PHP would determine the integer value of that string to be \`20\`. Strong /r/lolphp here for sure.<|eor|><|sor|>It would definitely make more sense to convert the int to a String and compare it. God sometimes PHP really doesn't make any sense...<|eor|><|sor|>Until you realise that you can (and should) use strict types.<|eor|><|sor|>Yes, that is absolutely correct. Still, this is a very strange behavior of PHP.<|eor|><|eols|><|endoftext|>
8
lolphp
Takeoded
fwn7c9y
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|sor|>You asked a stupid question and got a stupid answer. Not LOLPHP material.<|eor|><|soopr|>In no sane high-level language is `0` == `gfsdgsfdgsdf`, just ask Python or JavaScript i know the `==` operator is like the `kindof-equal` operator, but 0 is not even kindof equal to gfsdgsfdgsdf<|eoopr|><|eols|><|endoftext|>
7
lolphp
ricdesi
fwl2kcs
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|sor|>...wait, is it somehow reading that string as NaN, and just saying sure, falsey == falsey?<|eor|><|eols|><|endoftext|>
6
lolphp
Jonno_FTW
fwnqs0k
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|soopr|>come to think of it, PHP8 would be a good time to BC-break-fix whatever the fuck that is, wouldn't it? (bet they can't fix it in PHP7)<|eoopr|><|sor|>[deleted]<|eor|><|sor|>When is this kind of type coercion ever going to be useful? I can understand the case for something like `0 == '0'` but the above is just ridiculous.<|eor|><|eols|><|endoftext|>
5
lolphp
bart2019
g0k8svt
<|sols|><|sot|>0 == "gfsdgsfdgsdf"<|eot|><|sol|>https://3v4l.org/j8vDJ<|eol|><|sor|>Here's another similar one for fun: >php -r "var_dump('OK' == true);" bool(true)<|eor|><|sor|>>var\_dump('OK' == true); [https://www.php.net/manual/en/types.comparisons.php](https://www.php.net/manual/en/types.comparisons.php) **Loose comparisons** **rtfm**<|eor|><|sor|>STFU. JavaScript does loose comparisons the proper way. You don't convert a string to a boolean, you convert the boolean to a string.<|eor|><|eols|><|endoftext|>
5
lolphp
dotancohen
7sun0m
<|soss|><|sot|>ldap_connect() Note: This function does not open a connection<|eot|><|sost|>Apparently the fine function [ldap_connect()](http://php.net/manual/en/function.ldap-connect.php) creates an LDAP link identifier and checks whether the given host and port are plausible. IT DOES NOT OPEN A CONNECTION. Naming things is hard.<|eost|><|eoss|><|endoftext|>
93
lolphp
maweki
dt7ppyo
<|soss|><|sot|>ldap_connect() Note: This function does not open a connection<|eot|><|sost|>Apparently the fine function [ldap_connect()](http://php.net/manual/en/function.ldap-connect.php) creates an LDAP link identifier and checks whether the given host and port are plausible. IT DOES NOT OPEN A CONNECTION. Naming things is hard.<|eost|><|sor|>"ldap_connect Connect to an LDAP server" "Note: This function does not open a connection."<|eor|><|eoss|><|endoftext|>
49
lolphp
dagbrown
dt7qedo
<|soss|><|sot|>ldap_connect() Note: This function does not open a connection<|eot|><|sost|>Apparently the fine function [ldap_connect()](http://php.net/manual/en/function.ldap-connect.php) creates an LDAP link identifier and checks whether the given host and port are plausible. IT DOES NOT OPEN A CONNECTION. Naming things is hard.<|eost|><|sor|>This is the kind of thing that you'd use a *constructor* for. You know, like every other language in the world does. The actual connection is made when you call the `->bind()` method, but of course you knew that already.<|eor|><|eoss|><|endoftext|>
19
lolphp
kr094
dt7q7be
<|soss|><|sot|>ldap_connect() Note: This function does not open a connection<|eot|><|sost|>Apparently the fine function [ldap_connect()](http://php.net/manual/en/function.ldap-connect.php) creates an LDAP link identifier and checks whether the given host and port are plausible. IT DOES NOT OPEN A CONNECTION. Naming things is hard.<|eost|><|sor|>"...the provided hostname/port combination or LDAP URI seems plausible. It's a syntactic check of the provided parameters but the server(s) will not be contacted!" wow, just wow<|eor|><|eoss|><|endoftext|>
19
lolphp
masklinn
dtf10wi
<|soss|><|sot|>ldap_connect() Note: This function does not open a connection<|eot|><|sost|>Apparently the fine function [ldap_connect()](http://php.net/manual/en/function.ldap-connect.php) creates an LDAP link identifier and checks whether the given host and port are plausible. IT DOES NOT OPEN A CONNECTION. Naming things is hard.<|eost|><|sor|>This is the kind of thing that you'd use a *constructor* for. You know, like every other language in the world does. The actual connection is made when you call the `->bind()` method, but of course you knew that already.<|eor|><|sor|>But php functions don't have constructors (the fact this library isn't OO is large historical)<|eor|><|sor|>ldap_prepare would be a better name than ldap_connect. And even if its not OO, its still doing the job of a constructor. No action is taking place: its just setting up data structures for future action.<|eor|><|sor|>ldap_prepare, ldap_create, ldap_new, there's endless words more sensible.<|eor|><|eoss|><|endoftext|>
11
lolphp
dagbrown
dtcujuq
<|soss|><|sot|>ldap_connect() Note: This function does not open a connection<|eot|><|sost|>Apparently the fine function [ldap_connect()](http://php.net/manual/en/function.ldap-connect.php) creates an LDAP link identifier and checks whether the given host and port are plausible. IT DOES NOT OPEN A CONNECTION. Naming things is hard.<|eost|><|sor|>This is the kind of thing that you'd use a *constructor* for. You know, like every other language in the world does. The actual connection is made when you call the `->bind()` method, but of course you knew that already.<|eor|><|sor|>But php functions don't have constructors (the fact this library isn't OO is large historical)<|eor|><|sor|>ldap_prepare would be a better name than ldap_connect. And even if its not OO, its still doing the job of a constructor. No action is taking place: its just setting up data structures for future action.<|eor|><|eoss|><|endoftext|>
10
lolphp
ciaranmcnulty
dtcuf4s
<|soss|><|sot|>ldap_connect() Note: This function does not open a connection<|eot|><|sost|>Apparently the fine function [ldap_connect()](http://php.net/manual/en/function.ldap-connect.php) creates an LDAP link identifier and checks whether the given host and port are plausible. IT DOES NOT OPEN A CONNECTION. Naming things is hard.<|eost|><|sor|>This is the kind of thing that you'd use a *constructor* for. You know, like every other language in the world does. The actual connection is made when you call the `->bind()` method, but of course you knew that already.<|eor|><|sor|>But php functions don't have constructors (the fact this library isn't OO is large historical)<|eor|><|eoss|><|endoftext|>
6
lolphp
PuffyHerb
c395nr
<|sols|><|sot|>Using DateTime::ISO8601 is incompatible with ISO-8601 but left broken for backward compatibility. Use DateTime::ATOM instead when you need ISO8601<|eot|><|sol|>https://i.redd.it/3zjxohvaxo531.png<|eol|><|eols|><|endoftext|>
91
lolphp
Rogue2166
erpf0m8
<|sols|><|sot|>Using DateTime::ISO8601 is incompatible with ISO-8601 but left broken for backward compatibility. Use DateTime::ATOM instead when you need ISO8601<|eot|><|sol|>https://i.redd.it/3zjxohvaxo531.png<|eol|><|sor|>Jesus php, get the fuck out of here<|eor|><|eols|><|endoftext|>
19
lolphp
TheHalfBloodFriendly
erpqc4r
<|sols|><|sot|>Using DateTime::ISO8601 is incompatible with ISO-8601 but left broken for backward compatibility. Use DateTime::ATOM instead when you need ISO8601<|eot|><|sol|>https://i.redd.it/3zjxohvaxo531.png<|eol|><|sor|>Gotta love their comments on the issue tracker stating its not a bug > [https://bugs.php.net/bug.php?id=51950](https://bugs.php.net/bug.php?id=51950) > > Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at [http://www.php.net/manual/](http://www.php.net/manual/) and the instructions on how to report a bug at [http://bugs.php.net/how-to-report.php](http://bugs.php.net/how-to-report.php) > >DateTime::ISO8601 is defined to "Y-m-d\\TH:i:sO"\[1\], so obviously it doesn't accept microsecond fractions. If you expect these to be given, use another format specifier, see <[https://3v4l.org/ADn0l](https://3v4l.org/ADn0l)\>.<|eor|><|eols|><|endoftext|>
18
lolphp
shaql
erww8c0
<|sols|><|sot|>Using DateTime::ISO8601 is incompatible with ISO-8601 but left broken for backward compatibility. Use DateTime::ATOM instead when you need ISO8601<|eot|><|sol|>https://i.redd.it/3zjxohvaxo531.png<|eol|><|sor|>Duplicate of https://www.reddit.com/r/lolphp/comments/4oacnc/php_and_iso_8601_from_phpnet_link_in_comments/ (top6 alltime on this subreddit)<|eor|><|eols|><|endoftext|>
6
lolphp
Daniel15
5am6dz
<|sols|><|sot|>"must be an instance of boolean, boolean returned"<|eot|><|sol|>https://3v4l.org/qLv4E<|eol|><|eols|><|endoftext|>
92
lolphp
Daniel15
d9hhw9w
<|sols|><|sot|>"must be an instance of boolean, boolean returned"<|eot|><|sol|>https://3v4l.org/qLv4E<|eol|><|soopr|> function lol(): boolean { return true; } lol(); Results in: Uncaught TypeError: Return value of lol() must be an instance of boolean, boolean returned Because the type is actually called `bool`. Thanks for the helpful error message, PHP.<|eoopr|><|eols|><|endoftext|>
53
lolphp
polish_niceguy
d9hq50q
<|sols|><|sot|>"must be an instance of boolean, boolean returned"<|eot|><|sol|>https://3v4l.org/qLv4E<|eol|><|soopr|> function lol(): boolean { return true; } lol(); Results in: Uncaught TypeError: Return value of lol() must be an instance of boolean, boolean returned Because the type is actually called `bool`. Thanks for the helpful error message, PHP.<|eoopr|><|sor|>It gets better with integers, as the correct name is `integer`, not `int`. [Because PHP](https://3v4l.org/sXtvb).<|eor|><|eols|><|endoftext|>
36
lolphp
shvelo
d9i6npy
<|sols|><|sot|>"must be an instance of boolean, boolean returned"<|eot|><|sol|>https://3v4l.org/qLv4E<|eol|><|soopr|> function lol(): boolean { return true; } lol(); Results in: Uncaught TypeError: Return value of lol() must be an instance of boolean, boolean returned Because the type is actually called `bool`. Thanks for the helpful error message, PHP.<|eoopr|><|sor|>It gets better with integers, as the correct name is `integer`, not `int`. [Because PHP](https://3v4l.org/sXtvb).<|eor|><|sor|>It gets better `Argument 1 passed to lol() must be an instance of integer, integer given` https://3v4l.org/EsJXF<|eor|><|eols|><|endoftext|>
20
lolphp
Daniel15
d9hljxl
<|sols|><|sot|>"must be an instance of boolean, boolean returned"<|eot|><|sol|>https://3v4l.org/qLv4E<|eol|><|soopr|> function lol(): boolean { return true; } lol(); Results in: Uncaught TypeError: Return value of lol() must be an instance of boolean, boolean returned Because the type is actually called `bool`. Thanks for the helpful error message, PHP.<|eoopr|><|sor|>Wait... so is boolean an actual reserved word? Or can you just have an undefined type and PHP will try to check for it? Edit: [it's the latter](https://3v4l.org/N9pcr)<|eor|><|soopr|>boolean is not a reserved word, it's just treating it as the name of a class. You could make a new class called `boolean` and it'd pass the typecheck: https://3v4l.org/KfhEW <?php class boolean { } function lol(): boolean { return new boolean(); } lol();<|eoopr|><|eols|><|endoftext|>
19
lolphp
sloat
d9hla62
<|sols|><|sot|>"must be an instance of boolean, boolean returned"<|eot|><|sol|>https://3v4l.org/qLv4E<|eol|><|soopr|> function lol(): boolean { return true; } lol(); Results in: Uncaught TypeError: Return value of lol() must be an instance of boolean, boolean returned Because the type is actually called `bool`. Thanks for the helpful error message, PHP.<|eoopr|><|sor|>Wait... so is boolean an actual reserved word? Or can you just have an undefined type and PHP will try to check for it? Edit: [it's the latter](https://3v4l.org/N9pcr)<|eor|><|eols|><|endoftext|>
15
lolphp
Vakieh
d9iaxqx
<|sols|><|sot|>"must be an instance of boolean, boolean returned"<|eot|><|sol|>https://3v4l.org/qLv4E<|eol|><|sor|>This is why php should have just embraced its own truthiness and called all return types "something". It can probably auto cast from everything to everything, so just run with it.<|eor|><|eols|><|endoftext|>
10
lolphp
kkjdroid
d9idj6o
<|sols|><|sot|>"must be an instance of boolean, boolean returned"<|eot|><|sol|>https://3v4l.org/qLv4E<|eol|><|sor|>This is why php should have just embraced its own truthiness and called all return types "something". It can probably auto cast from everything to everything, so just run with it.<|eor|><|sor|>At that point, just be Python and don't have explicit return types. >you are doing that too much. try again in 8 minutes. I have more than 100k comment karma. I'm probably not a spambot. And if I am, I'm damn well clever enough to hide it.<|eor|><|eols|><|endoftext|>
7
lolphp
hylje
d9jsojr
<|sols|><|sot|>"must be an instance of boolean, boolean returned"<|eot|><|sol|>https://3v4l.org/qLv4E<|eol|><|sor|>This is why php should have just embraced its own truthiness and called all return types "something". It can probably auto cast from everything to everything, so just run with it.<|eor|><|sor|>At that point, just be Python and don't have explicit return types. >you are doing that too much. try again in 8 minutes. I have more than 100k comment karma. I'm probably not a spambot. And if I am, I'm damn well clever enough to hide it.<|eor|><|sor|>Comment cooldown is based on subreddit-local karma.<|eor|><|eols|><|endoftext|>
6
lolphp
Daniel15
d9izmac
<|sols|><|sot|>"must be an instance of boolean, boolean returned"<|eot|><|sol|>https://3v4l.org/qLv4E<|eol|><|sor|>This is why php should have just embraced its own truthiness and called all return types "something". It can probably auto cast from everything to everything, so just run with it.<|eor|><|sor|>At that point, just be Python and don't have explicit return types. >you are doing that too much. try again in 8 minutes. I have more than 100k comment karma. I'm probably not a spambot. And if I am, I'm damn well clever enough to hide it.<|eor|><|soopr|>> doing that too much I would do anything for love, but I won't do that<|eoopr|><|eols|><|endoftext|>
5
lolphp
maweki
46fxi8
<|sols|><|sot|>Typofixing commit in Mersenne twister RNG code is reverted (because code might depend on it)<|eot|><|sol|>https://github.com/php/php-src/commit/a0724d30817600540946b41e40f4cfc2a0c30f80<|eol|><|eols|><|endoftext|>
92
lolphp
midir
d04y0q0
<|sols|><|sot|>Typofixing commit in Mersenne twister RNG code is reverted (because code might depend on it)<|eot|><|sol|>https://github.com/php/php-src/commit/a0724d30817600540946b41e40f4cfc2a0c30f80<|eol|><|sor|>So in the future we'll have: * rand Generate a random integer * mt_rand Generate a better random integer * real_mt_rand Generate a better random integer properly<|eor|><|eols|><|endoftext|>
58
lolphp
phoshi
d04tgtq
<|sols|><|sot|>Typofixing commit in Mersenne twister RNG code is reverted (because code might depend on it)<|eot|><|sol|>https://github.com/php/php-src/commit/a0724d30817600540946b41e40f4cfc2a0c30f80<|eol|><|sor|>This commit is unfortunately not wrong. Producing repeatable sequences of pseudorandom numbers is an important part of a PRNG's job. It's time for another real_. <|eor|><|eols|><|endoftext|>
41
lolphp
cbraga
d058dkk
<|sols|><|sot|>Typofixing commit in Mersenne twister RNG code is reverted (because code might depend on it)<|eot|><|sol|>https://github.com/php/php-src/commit/a0724d30817600540946b41e40f4cfc2a0c30f80<|eol|><|sor|>So in the future we'll have: * rand Generate a random integer * mt_rand Generate a better random integer * real_mt_rand Generate a better random integer properly<|eor|><|sor|>omg can someone please make a pull request for this<|eor|><|eols|><|endoftext|>
25
lolphp
outadoc
d054jds
<|sols|><|sot|>Typofixing commit in Mersenne twister RNG code is reverted (because code might depend on it)<|eot|><|sol|>https://github.com/php/php-src/commit/a0724d30817600540946b41e40f4cfc2a0c30f80<|eol|><|sor|>This commit is unfortunately not wrong. Producing repeatable sequences of pseudorandom numbers is an important part of a PRNG's job. It's time for another real_. <|eor|><|soopr|>Repeatable in the sense that the original implementation does not repeat the numbers as the algorithm defines.<|eoopr|><|sor|>Yes. I can 100% guarantee it that there's software out there relying on the repeatable nature of the prng, and for good, purposeful reason. <|eor|><|sor|>That's why if you really need that you should own the code. A LCG is pretty simple to implement, and if you're feeling fancy you can roll your own MT and make sure its parameters stay the same.<|eor|><|sor|>But that's what libraries are for. You're not going to rewrite something that can be as fiddly and critical as a PRNG if you can help it. <|eor|><|eols|><|endoftext|>
22
lolphp
Scaliwag
d053lo0
<|sols|><|sot|>Typofixing commit in Mersenne twister RNG code is reverted (because code might depend on it)<|eot|><|sol|>https://github.com/php/php-src/commit/a0724d30817600540946b41e40f4cfc2a0c30f80<|eol|><|sor|>Did anyone check the output of the broken Mersenne-Twister if it's even random? (to the point that statistical tests exist that can check this)<|eor|><|sor|>For some time it didn't return even numbers so I guess there is a bit of bias in that regard, aside from that not really sure.<|eor|><|eols|><|endoftext|>
20
lolphp
kerzen1
d04qeb4
<|sols|><|sot|>Typofixing commit in Mersenne twister RNG code is reverted (because code might depend on it)<|eot|><|sol|>https://github.com/php/php-src/commit/a0724d30817600540946b41e40f4cfc2a0c30f80<|eol|><|sor|>Did anyone check the output of the broken Mersenne-Twister if it's even random? (to the point that statistical tests exist that can check this)<|eor|><|eols|><|endoftext|>
19
lolphp
phoshi
d04v1fy
<|sols|><|sot|>Typofixing commit in Mersenne twister RNG code is reverted (because code might depend on it)<|eot|><|sol|>https://github.com/php/php-src/commit/a0724d30817600540946b41e40f4cfc2a0c30f80<|eol|><|sor|>This commit is unfortunately not wrong. Producing repeatable sequences of pseudorandom numbers is an important part of a PRNG's job. It's time for another real_. <|eor|><|soopr|>Repeatable in the sense that the original implementation does not repeat the numbers as the algorithm defines.<|eoopr|><|sor|>Yes. I can 100% guarantee it that there's software out there relying on the repeatable nature of the prng, and for good, purposeful reason. <|eor|><|eols|><|endoftext|>
18
lolphp
the_alias_of_andrea
d054e8m
<|sols|><|sot|>Typofixing commit in Mersenne twister RNG code is reverted (because code might depend on it)<|eot|><|sol|>https://github.com/php/php-src/commit/a0724d30817600540946b41e40f4cfc2a0c30f80<|eol|><|sor|>So in the future we'll have: * rand Generate a random integer * mt_rand Generate a better random integer * real_mt_rand Generate a better random integer properly<|eor|><|sor|>Possibly, but we may well just fix it in 7.1. Fixing it in a patch release, though, there's a risk that's going to bite someone.<|eor|><|eols|><|endoftext|>
15