subreddit
stringclasses
7 values
author
stringlengths
3
20
id
stringlengths
5
7
content
stringlengths
67
30.4k
score
int64
0
140k
lolphp
ealf
j21bv
<|sols|><|sot|>Guess the output: echo(1) and print(2) and die(3);<|eot|><|sol|>http://writecodeonline.com/php/?code=echo%281%29+and+print%282%29+and+die%283%29%3B<|eol|><|eols|><|endoftext|>
15
lolphp
gwynjudd
c2eexj7
<|sols|><|sot|>Guess the output: echo(1) and print(2) and die(3);<|eot|><|sol|>http://writecodeonline.com/php/?code=echo%281%29+and+print%282%29+and+die%283%29%3B<|eol|><|sor|>I don't see the problem. Is your complaint that the expected type of the parameter isn't consistent across 3 differing functions?<|eor|><|soopr|>My complaints are mostly that * It is parsed as echo(1 && print(2) && die(3)) for sad, sad reasons. * exit(1) and die('1') works as anyone would expect. exit('1') and die(1) does not. EDIT: With the exception that die('foo') actually ends the program *successfully, with exit code 0*. Jesus! It. Just. Never. Ends.<|eoopr|><|sor|>>It is parsed as echo(1 && print(2) && die(3)) for sad, sad reasons. w t f<|eor|><|eols|><|endoftext|>
10
lolphp
ealf
c28mb11
<|sols|><|sot|>Guess the output: echo(1) and print(2) and die(3);<|eot|><|sol|>http://writecodeonline.com/php/?code=echo%281%29+and+print%282%29+and+die%283%29%3B<|eol|><|sor|>I don't see the problem. Is your complaint that the expected type of the parameter isn't consistent across 3 differing functions?<|eor|><|soopr|>My complaints are mostly that * It is parsed as echo(1 && print(2) && die(3)) for sad, sad reasons. * exit(1) and die('1') works as anyone would expect. exit('1') and die(1) does not. EDIT: With the exception that die('foo') actually ends the program *successfully, with exit code 0*. Jesus! It. Just. Never. Ends.<|eoopr|><|eols|><|endoftext|>
7
lolphp
tian2992
hcwbi
<|soss|><|sot|>print(42+"-"+1024);<|eot|><|sost|>1066 Casting tables gone mad.<|eost|><|eoss|><|endoftext|>
15
lolphp
Hazasoul
c35mgea
<|soss|><|sot|>print(42+"-"+1024);<|eot|><|sost|>1066 Casting tables gone mad.<|eost|><|sor|>Lua 5.1: > print(42+"-"+1024) stdin:1: attempt to perform arithmetic on a string value However, Lua also have some automatic conversions build in, just not braindead ones: > print(4+"2") 6 <|eor|><|sor|>(Sorry for the bump, but) I thought PHP used a period for concatenation?<|eor|><|eoss|><|endoftext|>
6
lolphp
wvenable
c2epitv
<|soss|><|sot|>print(42+"-"+1024);<|eot|><|sost|>1066 Casting tables gone mad.<|eost|><|sor|>What the...? I was expecting -982 or possibly 982. 1066 is positively boggling.<|eor|><|sor|>You seem to think there should be some string concatenation going on instead of addition, but those are separate operators in PHP. The result of 42 + "-" is 42 which is then added 1024. It's really the odd construction of the example that makes you think the result might be different. As a rule, if you're doing math in PHP you should really make sure the values that you are working with are actually numbers. <|eor|><|eoss|><|endoftext|>
6
lolphp
tian2992
c1uias2
<|soss|><|sot|>print(42+"-"+1024);<|eot|><|sost|>1066 Casting tables gone mad.<|eost|><|sor|>What the...? I was expecting -982 or possibly 982. 1066 is positively boggling.<|eor|><|soopr|>"-" gets casted to "-0"<|eoopr|><|eoss|><|endoftext|>
5
lolphp
pilif
10qner8
<|sols|><|sot|>DateTime silently corrupting unsupported data.<|eot|><|sol|>https://3v4l.org/2Tsuf<|eol|><|eols|><|endoftext|>
15
lolphp
funtek
j6r186l
<|sols|><|sot|>DateTime silently corrupting unsupported data.<|eot|><|sol|>https://3v4l.org/2Tsuf<|eol|><|sor|>Which is why you never let date functions guess the input format. This is true for most languages and date libraries. Compare: https://3v4l.org/vog1j<|eor|><|eols|><|endoftext|>
15
lolphp
elcapitanoooo
j6rupf7
<|sols|><|sot|>DateTime silently corrupting unsupported data.<|eot|><|sol|>https://3v4l.org/2Tsuf<|eol|><|sor|>Which is why you never let date functions guess the input format. This is true for most languages and date libraries. Compare: https://3v4l.org/vog1j<|eor|><|sor|>I dont see how is this lolphp defendable. A language should throw, if not during compile time, then at runtime. There is literally 0 benefit in not throwing; and even less benefit having somebody defend this horrible language design decision<|eor|><|sor|>It should throw instead of returning false, if it can't parse it. But it could parse it. You didn't specify how you want it parsed, so php parsed according to some internal rules. Lots of libraries do that. You should have specified the input format. If you don't, you agree to have it parsed any way php chooses.<|eor|><|sor|>> according to some internal rules Found the source for this subs existence.<|eor|><|eols|><|endoftext|>
15
lolphp
kyou20
j6rp3j4
<|sols|><|sot|>DateTime silently corrupting unsupported data.<|eot|><|sol|>https://3v4l.org/2Tsuf<|eol|><|sor|>Which is why you never let date functions guess the input format. This is true for most languages and date libraries. Compare: https://3v4l.org/vog1j<|eor|><|sor|>I dont see how is this lolphp defendable. A language should throw, if not during compile time, then at runtime. There is literally 0 benefit in not throwing; and even less benefit having somebody defend this horrible language design decision<|eor|><|eols|><|endoftext|>
12
lolphp
funtek
j6rroo4
<|sols|><|sot|>DateTime silently corrupting unsupported data.<|eot|><|sol|>https://3v4l.org/2Tsuf<|eol|><|sor|>Which is why you never let date functions guess the input format. This is true for most languages and date libraries. Compare: https://3v4l.org/vog1j<|eor|><|sor|>I dont see how is this lolphp defendable. A language should throw, if not during compile time, then at runtime. There is literally 0 benefit in not throwing; and even less benefit having somebody defend this horrible language design decision<|eor|><|sor|>It should throw instead of returning false, if it can't parse it. But it could parse it. You didn't specify how you want it parsed, so php parsed according to some internal rules. Lots of libraries do that. You should have specified the input format. If you don't, you agree to have it parsed any way php chooses.<|eor|><|eols|><|endoftext|>
9
lolphp
elcapitanoooo
j6ru0os
<|sols|><|sot|>DateTime silently corrupting unsupported data.<|eot|><|sol|>https://3v4l.org/2Tsuf<|eol|><|sor|>DateTime in PHP is such a clusterfuck. Have been bitten on so many occations. IIRC there was a bug that allowed you to modify an DateTimeImmutable object. Just mindbendingly bad Edit. Heres the datetime immutable bug in action. https://3v4l.org/rZD24#v5.6.17<|eor|><|eols|><|endoftext|>
8
lolphp
Alekzcb
j6u19qe
<|sols|><|sot|>DateTime silently corrupting unsupported data.<|eot|><|sol|>https://3v4l.org/2Tsuf<|eol|><|sor|>DateTime in PHP is such a clusterfuck. Have been bitten on so many occations. IIRC there was a bug that allowed you to modify an DateTimeImmutable object. Just mindbendingly bad Edit. Heres the datetime immutable bug in action. https://3v4l.org/rZD24#v5.6.17<|eor|><|sor|>It's bad, but it got nothing on JS native Date class. It treats days and years as expected, but somehow the month of January is equal to 0, February is 1, etc...<|eor|><|sor|>I learned that behaviour after it manifested in a particularly obtuse way. I was trying to parse a date similar to "2023-01-31", and the output I get I date object representing 2023-03-03, totally baffling. It's because it interprets "-01-" in the middle as February, instead of January as expected. But then instead of realising Feb 31st is an invalid date and throwing an error or something, JS decides to roll over into March. "Feb 31st" = Feb 1st + 30 days = Mar 3rd. Great, thanks, very helpful.<|eor|><|eols|><|endoftext|>
5
lolphp
Takeoded
fgaz6f
<|sols|><|sot|>boolval() doesn't agree with FILTER_VALIDATE_BOOLEAN<|eot|><|sol|>https://3v4l.org/bOrhG<|eol|><|eols|><|endoftext|>
14
lolphp
bj_christianson
fk3utd7
<|sols|><|sot|>boolval() doesn't agree with FILTER_VALIDATE_BOOLEAN<|eot|><|sol|>https://3v4l.org/bOrhG<|eol|><|sor|>The issue here is that `boolval()` is for language coercion, but `FILTER_VALIDATE_BOOLEAN` is for filtering web input. Some forms return "Off" or "On" for checkboxes. So the filter has to accept those values. But since `boolval()` is not meant for user input, it will use normal string to boolean conversion, which means any string other than `""` or `"0"` is true. Its different tools for different use cases.<|eor|><|eols|><|endoftext|>
19
lolphp
SirClueless
fk3wt7y
<|sols|><|sot|>boolval() doesn't agree with FILTER_VALIDATE_BOOLEAN<|eot|><|sol|>https://3v4l.org/bOrhG<|eol|><|sor|>The issue here is that `boolval()` is for language coercion, but `FILTER_VALIDATE_BOOLEAN` is for filtering web input. Some forms return "Off" or "On" for checkboxes. So the filter has to accept those values. But since `boolval()` is not meant for user input, it will use normal string to boolean conversion, which means any string other than `""` or `"0"` is true. Its different tools for different use cases.<|eor|><|sor|>None of this context is documented though. `filter_var` isn't documented as being for filtering web input. It just behaves differently and it's up to users to surmise what historical or practical reason was behind the inconsistent behavior. The vast majority of lolphp's are like this: there is a good reason things are the way that they are, it's just that the way things are is inconsistent and surprising and always will be for backwards compatibility reasons.<|eor|><|eols|><|endoftext|>
16
lolphp
Takeoded
eyocft
<|sols|><|sot|>how to call dynamically added methods<|eot|><|sol|>https://3v4l.org/MppBE<|eol|><|eols|><|endoftext|>
16
lolphp
sproingie
fgiqi3f
<|sols|><|sot|>how to call dynamically added methods<|eot|><|sol|>https://3v4l.org/MppBE<|eol|><|sor|>PHP methods and attributes are in different namespaces. `($o->f)()` works. Likely you won't have access to `$this` however.<|eor|><|eols|><|endoftext|>
17
lolphp
barubary
fgirdpv
<|sols|><|sot|>how to call dynamically added methods<|eot|><|sol|>https://3v4l.org/MppBE<|eol|><|sor|>Both `($o->f)()` and `call_user_func($o->f)` work.<|eor|><|eols|><|endoftext|>
9
lolphp
SerdanKK
fgjf0uu
<|sols|><|sot|>how to call dynamically added methods<|eot|><|sol|>https://3v4l.org/MppBE<|eol|><|sor|>PHP methods and attributes are in different namespaces. `($o->f)()` works. Likely you won't have access to `$this` however.<|eor|><|sor|>You can use `$this` if you bind the closure to an object. [https://3v4l.org/BklFB](https://3v4l.org/BklFB)<|eor|><|eols|><|endoftext|>
7
lolphp
barubary
fgk4wb6
<|sols|><|sot|>how to call dynamically added methods<|eot|><|sol|>https://3v4l.org/MppBE<|eol|><|sor|>PHP methods and attributes are in different namespaces. `($o->f)()` works. Likely you won't have access to `$this` however.<|eor|><|sor|>Wait so you can call variables that contain functions directly, but if the function is on the object you have to use this syntax to get the compiler to pick the right namespace? What an amazing language<|eor|><|sor|>It's because `$foo->bar` is an attribute, but `$foo->bar(...` is a method call. With variables it's unambiguous: `$foo()` is always a dynamic call of what's in `$foo` because you cannot have `$` in a function name. But if you want to call a function stored in a constant, you probably need `(foo)()`.<|eor|><|eols|><|endoftext|>
5
lolphp
Takeoded
ebfcoi
<|sols|><|sot|>FILTER_VALIDATE_BOOLEAN validates emptystring as bool<|eot|><|sol|>https://3v4l.org/lpE2l<|eol|><|eols|><|endoftext|>
14
lolphp
SaltineAmerican_1970
fb4ztju
<|sols|><|sot|>FILTER_VALIDATE_BOOLEAN validates emptystring as bool<|eot|><|sol|>https://3v4l.org/lpE2l<|eol|><|sor|>> IfFILTER_NULL_ON_FAILUREis set,FALSEis returned only for "0", "false", "off", "no", and "", andNULLis returned for all non-boolean values. Edit: https://www.php.net/manual/en/filter.filters.validate.php<|eor|><|eols|><|endoftext|>
6
lolphp
philsturgeon
2xaenk
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|eoss|><|endoftext|>
11
lolphp
tdammers
coyuiph
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|eoss|><|endoftext|>
29
lolphp
_vec_
coyg8t3
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>Okay, so about your "Exhibit A". It's describing a (popular and likely to be approved) RFC. In laymans terms, it's a proposal for new behavior in the next version of PHP. The current behavior is, as demonstrated, to throw an error when the wrong type is passed in for a type-hinted argument. However, that type hint only works for instances of user-defined classes. You can't type-hint that something should be an actual boolean (i.e. `true` or `false`), and in fact trying to pass those in to your example raises [the same error](http://3v4l.org/9tk07). The [RFC](https://wiki.php.net/rfc/scalar_type_hints) proposes a new fix for this by special casing the words `int`, `integer`, `float`, `string`, `bool` and `boolean` to refer to the relevant builtin types instead of to user-defined classes, which is all well and good. However, according to the proposal these new hints should not raise an error when the wrong type of thing is passed in. Instead, unless an off-by-default flag is explicitly set, they will implicitly coerce to the specified type. If approved and implemented as proposed, the next version of PHP will behave exactly as described in the linked post. In short, the current behavior is surprising to users who aren't aware of the user-defined only limitation and fails with a confusing error. The PHP team apparently agrees and is seeking to add new behavior to the language, but is currently planning on doing so in a way which is inconsistent with the existing feature and will create more special-case exceptions which developers will need to be aware of. That seems worthy of inclusion in this forum to me.<|eor|><|eoss|><|endoftext|>
11
lolphp
tdammers
cp02ogr
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|sor|>Very slight correction: > This attitude is the real problem with ~~PHP~~ *programmers*. While perhaps common in the PHP community, it's common in many other popular programming communities. I think the distinction you point to is that it's strong in the core PHP dev group both present and historical. Most languages either have better foundations (e.g. Java) or worked hard to claw their way back to sanity from a modest start (e.g. Python 1.x). <|eor|><|sor|>Most other programming communities have a culture where people do patch up symptoms and commit hack jobs to get things done, but when they do they are ashamed and know that they are piling up technical debt; they generally try to do things right, but acknowledge that nobody is perfect, and the perfect situation does not always arise, so they seek a workable balance. The PHP community, however, seems to be mostly oblivious of information theory, abstract thinking, and keeping things manageable.<|eor|><|eoss|><|endoftext|>
9
lolphp
tdammers
coz1aq7
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|soopr|>You're using some "they all do this" example to behavior that some people do. Not really sure what the point is there. Regardless of what overly defensive PHP fanboys might say, that sort of conversation is not the problem. My problem is people just making shit up completely. <|eoopr|><|sor|>Not everyone does it, and I didn't say that. It's not just some rotten apples though; it is an attitude that permeates the PHP culture, and even the PHP core developers are deeply rooted in it. Making shit up is obviously not OK, I'm totally with you on this one. My point, I guess, is that posting random symptoms of PHP's underlying brokenness is completely pointless and not helping anyone. It's much worse when it's made up, but even when it's not, it doesn't help fix the problem, it only supports the kind of attitude that says "if only we spend enough time patching all the symptoms away, we'll end up with something really good".<|eor|><|eoss|><|endoftext|>
9
lolphp
allthediamonds
coygzvt
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>Okay, so about your "Exhibit A". It's describing a (popular and likely to be approved) RFC. In laymans terms, it's a proposal for new behavior in the next version of PHP. The current behavior is, as demonstrated, to throw an error when the wrong type is passed in for a type-hinted argument. However, that type hint only works for instances of user-defined classes. You can't type-hint that something should be an actual boolean (i.e. `true` or `false`), and in fact trying to pass those in to your example raises [the same error](http://3v4l.org/9tk07). The [RFC](https://wiki.php.net/rfc/scalar_type_hints) proposes a new fix for this by special casing the words `int`, `integer`, `float`, `string`, `bool` and `boolean` to refer to the relevant builtin types instead of to user-defined classes, which is all well and good. However, according to the proposal these new hints should not raise an error when the wrong type of thing is passed in. Instead, unless an off-by-default flag is explicitly set, they will implicitly coerce to the specified type. If approved and implemented as proposed, the next version of PHP will behave exactly as described in the linked post. In short, the current behavior is surprising to users who aren't aware of the user-defined only limitation and fails with a confusing error. The PHP team apparently agrees and is seeking to add new behavior to the language, but is currently planning on doing so in a way which is inconsistent with the existing feature and will create more special-case exceptions which developers will need to be aware of. That seems worthy of inclusion in this forum to me.<|eor|><|sor|>Actually, OP is right. If you click on the link they put there as "nope", you'll see they're referring to the output from the RFC branch. I just checked both the original RFC and its latest revision and both seem to specify that conversions between booleans and objects are not valid (see the "Behaviour of weak type checks" version) even when `strict_types=0`.<|eor|><|eoss|><|endoftext|>
8
lolphp
EsperSpirit
cp5ko56
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|soopr|>You're using some "they all do this" example to behavior that some people do. Not really sure what the point is there. Regardless of what overly defensive PHP fanboys might say, that sort of conversation is not the problem. My problem is people just making shit up completely. <|eoopr|><|sor|>Not everyone does it, and I didn't say that. It's not just some rotten apples though; it is an attitude that permeates the PHP culture, and even the PHP core developers are deeply rooted in it. Making shit up is obviously not OK, I'm totally with you on this one. My point, I guess, is that posting random symptoms of PHP's underlying brokenness is completely pointless and not helping anyone. It's much worse when it's made up, but even when it's not, it doesn't help fix the problem, it only supports the kind of attitude that says "if only we spend enough time patching all the symptoms away, we'll end up with something really good".<|eor|><|soopr|>Gotcha. > "if only we spend enough time patching all the symptoms away, we'll end up with something really good". I feel like that opinion is based on the assumption that these examples are only being patched away, and not solved at a higher level by fixing inconsistencies in the language. These RFCs are all approved for PHP 7: https://wiki.php.net/rfc/integer_semantics https://wiki.php.net/rfc/php7_foreach https://wiki.php.net/rfc/uniform_variable_syntax https://wiki.php.net/rfc/size_t_and_int64_next https://wiki.php.net/rfc/fix_list_behavior_inconsistency Inconsistencies are being nailed at a solid rate. The introduction of an AST in PHP 7 is helping a lot too. "Really good" is subjective, but it's not as awful as it used to be and it's consistently getting better, not just a pile ofduct-tape and string.<|eoopr|><|sor|>The problem is: While other languages (Clojure, Haskell, Scala, even Python3.4 or Java 8) push boundaries and try to make programming as a whole better on a conceptual level, PHP is still stuck fixing basic problems other languages didn't have from the get-go. And even if PHP7 somehow reinvents itself, it will not be adopted widely, because it will have to be incompatible with PHP5 to fix its problems. All those CMS and e-shops and forum software making up a large portion of the internet (always cited by people like you)? That will not be ported to PHP7 anytime soon and many php-devs will have to work with legacy sucky versions for quite some time to support existing stuff.<|eor|><|eoss|><|endoftext|>
8
lolphp
thallippoli
cozn2rf
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|soopr|>You're using some "they all do this" example to behavior that some people do. Not really sure what the point is there. Regardless of what overly defensive PHP fanboys might say, that sort of conversation is not the problem. My problem is people just making shit up completely. <|eoopr|><|sor|>Not everyone does it, and I didn't say that. It's not just some rotten apples though; it is an attitude that permeates the PHP culture, and even the PHP core developers are deeply rooted in it. Making shit up is obviously not OK, I'm totally with you on this one. My point, I guess, is that posting random symptoms of PHP's underlying brokenness is completely pointless and not helping anyone. It's much worse when it's made up, but even when it's not, it doesn't help fix the problem, it only supports the kind of attitude that says "if only we spend enough time patching all the symptoms away, we'll end up with something really good".<|eor|><|soopr|>Gotcha. > "if only we spend enough time patching all the symptoms away, we'll end up with something really good". I feel like that opinion is based on the assumption that these examples are only being patched away, and not solved at a higher level by fixing inconsistencies in the language. These RFCs are all approved for PHP 7: https://wiki.php.net/rfc/integer_semantics https://wiki.php.net/rfc/php7_foreach https://wiki.php.net/rfc/uniform_variable_syntax https://wiki.php.net/rfc/size_t_and_int64_next https://wiki.php.net/rfc/fix_list_behavior_inconsistency Inconsistencies are being nailed at a solid rate. The introduction of an AST in PHP 7 is helping a lot too. "Really good" is subjective, but it's not as awful as it used to be and it's consistently getting better, not just a pile ofduct-tape and string.<|eoopr|><|sor|>>Inconsistencies are being nailed at a solid rate... You just don't get it. Do you? For one thing most of these relevant fixes will break BC horribly and will never be approved and even if they are approved the quality of the fixes are outrageous (Mutable Datetime object? Closures that does not close over?). Because these are done by total amateurs (Opinion based on my conversation with some of them here and on the broken implementation of current php features.), these fixes are never good enough and only helps in winning arguments like the one's we are having here. >it's not as awful as it used to be and it's consistently getting better... Oh yea, it is. You see, the awfulness is the defining feature of the language. If you make in not-awful, it won't be PHP. The awfulness is the price that PHP paid for getting popular. (The presence of the 'Array' in php is a good example). So the awfulness that I am indicating goes into much deeper level than you see now (Hence the reason you still harbor hopes for PHP) and cannot be fixed. So I am sure you, (or anyone currently in 'love' with the language) can't be convinced the true nature of the language. I think that realization should come from within, and it will come if you keep an open mind (Might be hard to do if your brain is damaged by PHP use. No kidding) and is well exposed to other languages. But it takes time, and I don't want new programmers to waste time (7 or 8 years) for that realization, they better off start with another language. Hence I am replying to you only for the sake of other beginner programmer who might come across this thread. You see, there is no reason for people to cling to this language today. PHP was a language for web when it(web) was young. People still using it out of their choice are like kids who refuse to grow up and want to still ride 3 wheeled toy cycles. i wish people just let go and let php go into maintenance mode and die eventually...<|eor|><|eoss|><|endoftext|>
8
lolphp
tdammers
cp132ca
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|soopr|>You're using some "they all do this" example to behavior that some people do. Not really sure what the point is there. Regardless of what overly defensive PHP fanboys might say, that sort of conversation is not the problem. My problem is people just making shit up completely. <|eoopr|><|sor|>Not everyone does it, and I didn't say that. It's not just some rotten apples though; it is an attitude that permeates the PHP culture, and even the PHP core developers are deeply rooted in it. Making shit up is obviously not OK, I'm totally with you on this one. My point, I guess, is that posting random symptoms of PHP's underlying brokenness is completely pointless and not helping anyone. It's much worse when it's made up, but even when it's not, it doesn't help fix the problem, it only supports the kind of attitude that says "if only we spend enough time patching all the symptoms away, we'll end up with something really good".<|eor|><|soopr|>Gotcha. > "if only we spend enough time patching all the symptoms away, we'll end up with something really good". I feel like that opinion is based on the assumption that these examples are only being patched away, and not solved at a higher level by fixing inconsistencies in the language. These RFCs are all approved for PHP 7: https://wiki.php.net/rfc/integer_semantics https://wiki.php.net/rfc/php7_foreach https://wiki.php.net/rfc/uniform_variable_syntax https://wiki.php.net/rfc/size_t_and_int64_next https://wiki.php.net/rfc/fix_list_behavior_inconsistency Inconsistencies are being nailed at a solid rate. The introduction of an AST in PHP 7 is helping a lot too. "Really good" is subjective, but it's not as awful as it used to be and it's consistently getting better, not just a pile ofduct-tape and string.<|eoopr|><|sor|>Well... I sure hope you're right, and maybe things are really improving, but as far as I'm concerned, that ship has sailed, I'm out. It's not as bad as it used to be, but there's still a lot of ground to cover until "not embarrassing", IMO. And it's a bit awkward how the community is pointing out that PHP is awesome because it is now on its way to having all the basic features that all the other platforms have had for a decade now.<|eor|><|soopr|>Absolutely. As we grow as developers it's very natural for us to find new or different languages. Work takes us in various directions I've been using Rails and Go over the last few months and no PHP at all, but I did spent 15 years building what I consider to be an awesome career out of the language and I've seen it improve a lot. PHP is a necessary evil. It's simple enough that any muppet can easily make things with it, and it's great for huge teams that need a lot of developers that aren't necessarily CS experts. While we as developers might move on to languages that focus on specific use cases, PHP is always going to be there and the better it can get the better for everyone. Sitting around and pretending its all still as awful as it was in the PHP 4 days, or even PHP < 5.3 is not helping anyone. Nobody that uses it pretends its perfect, but it does get a lot of shit for things that are utter non-issues, issues that have been fixed for years, or issues that will be fixed in the next version. :)<|eoopr|><|sor|>> PHP is a necessary evil. It's simple enough that any muppet can easily make things with it, and it's great for huge teams that need a lot of developers that aren't necessarily CS experts. True, but I'd draw the opposite conclusion: PHP has done a lot of harm to programming and the internet, *because* every muppet can easily make (broken) things with it, and it fosters the mindset that creates huge teams with lots of developers that have insufficient knowledge of CS basics (the brute-force approach to building software development teams - I don't buy into that at all). > While we as developers might move on to languages that focus on specific use cases, ... Au contraire. PHP is the one that focuses on a specific use case; abusing it as a general-purpose language is what got us into this mess in the first place. PHP is (and, I guess, will be for quite some time) a niche language for quickly adding some incorrect but good enough dynamic scripting to what started as a static website; it still does that pretty well, sacrificing security, correctness and abstraction power for straightforward deployment, noob-friendliness and a seamless transition from static HTML to something like Wordpress. But the languages that people (including myself) are running to are not special-purpose languages for specific use cases; they are general-purpose languages used for all sorts of things, including but not limited to web applications and more or less dynamic websites. Python, Ruby, Java, C#, heck, even JavaScript, they are all more general and more versatile than PHP as far as application domains go. > PHP is always going to be there and the better it can get the better for everyone. I'm still kind of doubtful about this. "Is always going to be there" is obviously true in a trivial way, just like PDP-11 assembly and punch cards are still there, but I do hope that its eventual fate is going to be similar. Be that as it may; I am unsure whether I should applaud recent efforts for making PHP slightly more tolerable, or whether I should file them as unethical for blowing new life into PHP.<|eor|><|eoss|><|endoftext|>
7
lolphp
cparen
coz2yo5
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|sor|>Very slight correction: > This attitude is the real problem with ~~PHP~~ *programmers*. While perhaps common in the PHP community, it's common in many other popular programming communities. I think the distinction you point to is that it's strong in the core PHP dev group both present and historical. Most languages either have better foundations (e.g. Java) or worked hard to claw their way back to sanity from a modest start (e.g. Python 1.x). <|eor|><|eoss|><|endoftext|>
5
lolphp
iheartrms
coyhk7y
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>I also question the posting of bad programming. That is, something that has nothing to do with PHP, but "code that a bad programmer wrote, which happens to be in PHP."<|eor|><|sor|>Indeed. Correlation != Causation, even though the correlation between PHP and bad code is nearly equal to 1.<|eor|><|eoss|><|endoftext|>
5
lolphp
philsturgeon
coz4ccm
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|soopr|>You're using some "they all do this" example to behavior that some people do. Not really sure what the point is there. Regardless of what overly defensive PHP fanboys might say, that sort of conversation is not the problem. My problem is people just making shit up completely. <|eoopr|><|sor|>Not everyone does it, and I didn't say that. It's not just some rotten apples though; it is an attitude that permeates the PHP culture, and even the PHP core developers are deeply rooted in it. Making shit up is obviously not OK, I'm totally with you on this one. My point, I guess, is that posting random symptoms of PHP's underlying brokenness is completely pointless and not helping anyone. It's much worse when it's made up, but even when it's not, it doesn't help fix the problem, it only supports the kind of attitude that says "if only we spend enough time patching all the symptoms away, we'll end up with something really good".<|eor|><|soopr|>Gotcha. > "if only we spend enough time patching all the symptoms away, we'll end up with something really good". I feel like that opinion is based on the assumption that these examples are only being patched away, and not solved at a higher level by fixing inconsistencies in the language. These RFCs are all approved for PHP 7: https://wiki.php.net/rfc/integer_semantics https://wiki.php.net/rfc/php7_foreach https://wiki.php.net/rfc/uniform_variable_syntax https://wiki.php.net/rfc/size_t_and_int64_next https://wiki.php.net/rfc/fix_list_behavior_inconsistency Inconsistencies are being nailed at a solid rate. The introduction of an AST in PHP 7 is helping a lot too. "Really good" is subjective, but it's not as awful as it used to be and it's consistently getting better, not just a pile ofduct-tape and string.<|eoopr|><|eoss|><|endoftext|>
5
lolphp
tdammers
cp026d8
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|soopr|>You're using some "they all do this" example to behavior that some people do. Not really sure what the point is there. Regardless of what overly defensive PHP fanboys might say, that sort of conversation is not the problem. My problem is people just making shit up completely. <|eoopr|><|sor|>Not everyone does it, and I didn't say that. It's not just some rotten apples though; it is an attitude that permeates the PHP culture, and even the PHP core developers are deeply rooted in it. Making shit up is obviously not OK, I'm totally with you on this one. My point, I guess, is that posting random symptoms of PHP's underlying brokenness is completely pointless and not helping anyone. It's much worse when it's made up, but even when it's not, it doesn't help fix the problem, it only supports the kind of attitude that says "if only we spend enough time patching all the symptoms away, we'll end up with something really good".<|eor|><|soopr|>Gotcha. > "if only we spend enough time patching all the symptoms away, we'll end up with something really good". I feel like that opinion is based on the assumption that these examples are only being patched away, and not solved at a higher level by fixing inconsistencies in the language. These RFCs are all approved for PHP 7: https://wiki.php.net/rfc/integer_semantics https://wiki.php.net/rfc/php7_foreach https://wiki.php.net/rfc/uniform_variable_syntax https://wiki.php.net/rfc/size_t_and_int64_next https://wiki.php.net/rfc/fix_list_behavior_inconsistency Inconsistencies are being nailed at a solid rate. The introduction of an AST in PHP 7 is helping a lot too. "Really good" is subjective, but it's not as awful as it used to be and it's consistently getting better, not just a pile ofduct-tape and string.<|eoopr|><|sor|>Well... I sure hope you're right, and maybe things are really improving, but as far as I'm concerned, that ship has sailed, I'm out. It's not as bad as it used to be, but there's still a lot of ground to cover until "not embarrassing", IMO. And it's a bit awkward how the community is pointing out that PHP is awesome because it is now on its way to having all the basic features that all the other platforms have had for a decade now.<|eor|><|eoss|><|endoftext|>
5
lolphp
philsturgeon
cp0810x
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|soopr|>You're using some "they all do this" example to behavior that some people do. Not really sure what the point is there. Regardless of what overly defensive PHP fanboys might say, that sort of conversation is not the problem. My problem is people just making shit up completely. <|eoopr|><|sor|>Not everyone does it, and I didn't say that. It's not just some rotten apples though; it is an attitude that permeates the PHP culture, and even the PHP core developers are deeply rooted in it. Making shit up is obviously not OK, I'm totally with you on this one. My point, I guess, is that posting random symptoms of PHP's underlying brokenness is completely pointless and not helping anyone. It's much worse when it's made up, but even when it's not, it doesn't help fix the problem, it only supports the kind of attitude that says "if only we spend enough time patching all the symptoms away, we'll end up with something really good".<|eor|><|soopr|>Gotcha. > "if only we spend enough time patching all the symptoms away, we'll end up with something really good". I feel like that opinion is based on the assumption that these examples are only being patched away, and not solved at a higher level by fixing inconsistencies in the language. These RFCs are all approved for PHP 7: https://wiki.php.net/rfc/integer_semantics https://wiki.php.net/rfc/php7_foreach https://wiki.php.net/rfc/uniform_variable_syntax https://wiki.php.net/rfc/size_t_and_int64_next https://wiki.php.net/rfc/fix_list_behavior_inconsistency Inconsistencies are being nailed at a solid rate. The introduction of an AST in PHP 7 is helping a lot too. "Really good" is subjective, but it's not as awful as it used to be and it's consistently getting better, not just a pile ofduct-tape and string.<|eoopr|><|sor|>Well... I sure hope you're right, and maybe things are really improving, but as far as I'm concerned, that ship has sailed, I'm out. It's not as bad as it used to be, but there's still a lot of ground to cover until "not embarrassing", IMO. And it's a bit awkward how the community is pointing out that PHP is awesome because it is now on its way to having all the basic features that all the other platforms have had for a decade now.<|eor|><|soopr|>Absolutely. As we grow as developers it's very natural for us to find new or different languages. Work takes us in various directions I've been using Rails and Go over the last few months and no PHP at all, but I did spent 15 years building what I consider to be an awesome career out of the language and I've seen it improve a lot. PHP is a necessary evil. It's simple enough that any muppet can easily make things with it, and it's great for huge teams that need a lot of developers that aren't necessarily CS experts. While we as developers might move on to languages that focus on specific use cases, PHP is always going to be there and the better it can get the better for everyone. Sitting around and pretending its all still as awful as it was in the PHP 4 days, or even PHP < 5.3 is not helping anyone. Nobody that uses it pretends its perfect, but it does get a lot of shit for things that are utter non-issues, issues that have been fixed for years, or issues that will be fixed in the next version. :)<|eoopr|><|eoss|><|endoftext|>
5
lolphp
philsturgeon
cp004e7
<|soss|><|sot|>Patently False Code/Examples<|eot|><|sost|>I've notice a bit of a trend here, with people posting things that are patently false and then laughing about PHP for it. I'll sit with you and laugh at weird behaviors in PHP when it's actually a mess. I'll send them to [phpsadness.com](http://phpsadness.com) and see if I can fix them, or find somebody that can. But posting lies just to get your jollies is a really odd thing to do. Sometimes, these are not intentional, but when people posting these utterly incorrect examples are faced with the fact that they are wrong, do they delete the post? No, they leave it there and sandbag the discussions explaining their wrongness with trolling. [Exhibit A](http://www.reddit.com/r/lolphp/comments/2qyuhc/new_rfc_for_scalar_types_in_php_7/) - Apparently `foo(new stdClass())` is a valid value when passed in a `function foo(bool $bar)` function signature. Well... [nope.](http://3v4l.org/sPpRs/rfc#rfc-scalar_type_hints_v5) It will error: > Catchable fatal error: Argument 1 passed to foo() must be an instance of bool, instance of stdClass given Nothing lolphp there. Have a laugh about actual problems, but don't just walk around making things up.<|eost|><|sor|>The real danger of posting concrete examples of PHP failures (whether those are actual bugs, lies, or exhibits of clueless PHP programming is actually not that important in this regard) is that it triggers the "pragmatic" defense mechanism of the PHP community, of which OP is a textbook example. It works something like this. Critic: "PHP is broken, because it does X wrong." PHP: "Can you provide an example?" Critic: *provides example* PHP: *fixes example, or points out a workaround* Critic: "You have only fixed this one example, but X is still fundamentally broken" PHP: "Can you provide another example?" This attitude is the *real* problem with PHP. Each individual bug and issue and whatever you want to call them gets patched away eventually, but there is no unifying principle, no vision, no consistent philosophy to the whole thing, and probably never will be. And this means the only way one can get things done in PHP is to join in with the shotgun debugging crowd, and rather than think things through and go with what is conceptually and theoretically sound, just pump out something that's close enough and then bash it into shape. Trial-and-error-driven development. And don't even ask; no, I will not provide examples.<|eor|><|soopr|>You're using some "they all do this" example to behavior that some people do. Not really sure what the point is there. Regardless of what overly defensive PHP fanboys might say, that sort of conversation is not the problem. My problem is people just making shit up completely. <|eoopr|><|sor|>Not everyone does it, and I didn't say that. It's not just some rotten apples though; it is an attitude that permeates the PHP culture, and even the PHP core developers are deeply rooted in it. Making shit up is obviously not OK, I'm totally with you on this one. My point, I guess, is that posting random symptoms of PHP's underlying brokenness is completely pointless and not helping anyone. It's much worse when it's made up, but even when it's not, it doesn't help fix the problem, it only supports the kind of attitude that says "if only we spend enough time patching all the symptoms away, we'll end up with something really good".<|eor|><|soopr|>Gotcha. > "if only we spend enough time patching all the symptoms away, we'll end up with something really good". I feel like that opinion is based on the assumption that these examples are only being patched away, and not solved at a higher level by fixing inconsistencies in the language. These RFCs are all approved for PHP 7: https://wiki.php.net/rfc/integer_semantics https://wiki.php.net/rfc/php7_foreach https://wiki.php.net/rfc/uniform_variable_syntax https://wiki.php.net/rfc/size_t_and_int64_next https://wiki.php.net/rfc/fix_list_behavior_inconsistency Inconsistencies are being nailed at a solid rate. The introduction of an AST in PHP 7 is helping a lot too. "Really good" is subjective, but it's not as awful as it used to be and it's consistently getting better, not just a pile ofduct-tape and string.<|eoopr|><|sor|>>Inconsistencies are being nailed at a solid rate... You just don't get it. Do you? For one thing most of these relevant fixes will break BC horribly and will never be approved and even if they are approved the quality of the fixes are outrageous (Mutable Datetime object? Closures that does not close over?). Because these are done by total amateurs (Opinion based on my conversation with some of them here and on the broken implementation of current php features.), these fixes are never good enough and only helps in winning arguments like the one's we are having here. >it's not as awful as it used to be and it's consistently getting better... Oh yea, it is. You see, the awfulness is the defining feature of the language. If you make in not-awful, it won't be PHP. The awfulness is the price that PHP paid for getting popular. (The presence of the 'Array' in php is a good example). So the awfulness that I am indicating goes into much deeper level than you see now (Hence the reason you still harbor hopes for PHP) and cannot be fixed. So I am sure you, (or anyone currently in 'love' with the language) can't be convinced the true nature of the language. I think that realization should come from within, and it will come if you keep an open mind (Might be hard to do if your brain is damaged by PHP use. No kidding) and is well exposed to other languages. But it takes time, and I don't want new programmers to waste time (7 or 8 years) for that realization, they better off start with another language. Hence I am replying to you only for the sake of other beginner programmer who might come across this thread. You see, there is no reason for people to cling to this language today. PHP was a language for web when it(web) was young. People still using it out of their choice are like kids who refuse to grow up and want to still ride 3 wheeled toy cycles. i wish people just let go and let php go into maintenance mode and die eventually...<|eor|><|soopr|>You just said literally nothing. You made zero points, other than wanging on about how much you don't like PHP. > For one thing most of these relevant fixes will break BC horribly They do not. > and will never be approved They have been approved already. > and even if they are approved the quality of the fixes are outrageous (Mutable Datetime object? Closures that does not close over?) What now? The mutable Datetime object is old, and the immutable object was added a while ago. You need to tell me what the heck you're on about. > Because these are done by total amateurs Actually they're some of the smartest people I know. Facebook and Google don't hire amatures. The rest of that was you complaining about PHP a lot, and assuming that I don't know a bunch of other languages.<|eoopr|><|eoss|><|endoftext|>
5
lolphp
Altreus
x0pbp
<|sols|><|sot|>When I actually looked up empty() for this post I discovered half of my point was made for me.<|eot|><|sol|>http://altreus.blogspot.co.uk/2012/07/empty-considered-harmful.html<|eol|><|eols|><|endoftext|>
12
lolphp
alx5000
c5i61n1
<|sols|><|sot|>When I actually looked up empty() for this post I discovered half of my point was made for me.<|eot|><|sol|>http://altreus.blogspot.co.uk/2012/07/empty-considered-harmful.html<|eol|><|sor|>I guess the rationale for this is that you can avoid doing an extra isset(). For example, I can easily do if (empty($_GET['param'])) { /* */ } and check whether there's a GET variable called 'param' that has a non-null value. Hell, it even says so in the docs: > That means empty() is essentially the concise equivalent to !isset($var) || $var == false. The key word being "concise".<|eor|><|eols|><|endoftext|>
8
lolphp
imMute
c5ib369
<|sols|><|sot|>When I actually looked up empty() for this post I discovered half of my point was made for me.<|eot|><|sol|>http://altreus.blogspot.co.uk/2012/07/empty-considered-harmful.html<|eol|><|sor|>Is this guy serious? I would say this is one of the best features of PHP. If you want to check if something exists, use isset(), god damn it's not that hard. empty() allows you to not have to do, if (isset($var) && !empty($var)), every single time. Furthermore, why would you variable not be set? I don't think I ever run into an instance where a variable hasn't been declared.<|eor|><|sor|>dude. now check out how this is done in a sane language. really. why do you need an empty() when you're doing if ($_GET['things']) { ... ? you've never ever ever mispelled a variable? overlooked something that caused a variable to be undefined? (i don't understand your use of "declare" in that sentence, php has no such concept)<|eor|><|sor|>>you've never ever ever mispelled a variable? I have, but Perl complains loudly when I do.<|eor|><|eols|><|endoftext|>
8
lolphp
gearvOsh
c5i76l9
<|sols|><|sot|>When I actually looked up empty() for this post I discovered half of my point was made for me.<|eot|><|sol|>http://altreus.blogspot.co.uk/2012/07/empty-considered-harmful.html<|eol|><|sor|>Is this guy serious? I would say this is one of the best features of PHP. If you want to check if something exists, use isset(), god damn it's not that hard. empty() allows you to not have to do, if (isset($var) && !empty($var)), every single time. Furthermore, why would you variable not be set? I don't think I ever run into an instance where a variable hasn't been declared.<|eor|><|eols|><|endoftext|>
5
lolphp
huf
c5ibdn9
<|sols|><|sot|>When I actually looked up empty() for this post I discovered half of my point was made for me.<|eot|><|sol|>http://altreus.blogspot.co.uk/2012/07/empty-considered-harmful.html<|eol|><|sor|>Is this guy serious? I would say this is one of the best features of PHP. If you want to check if something exists, use isset(), god damn it's not that hard. empty() allows you to not have to do, if (isset($var) && !empty($var)), every single time. Furthermore, why would you variable not be set? I don't think I ever run into an instance where a variable hasn't been declared.<|eor|><|sor|>dude. now check out how this is done in a sane language. really. why do you need an empty() when you're doing if ($_GET['things']) { ... ? you've never ever ever mispelled a variable? overlooked something that caused a variable to be undefined? (i don't understand your use of "declare" in that sentence, php has no such concept)<|eor|><|sor|>>you've never ever ever mispelled a variable? I have, but Perl complains loudly when I do.<|eor|><|sor|>and this was the point ;)<|eor|><|eols|><|endoftext|>
5
lolphp
Altreus
wtkcl
<|sols|><|sot|>Today's PHP-induced bug: arbitrary object properties (PHP fucks me off daily so I've decided to chronicle it)<|eot|><|sol|>http://altreus.blogspot.co.uk/2012/07/todays-php-induced-bug-arbitrary-object.html<|eol|><|eols|><|endoftext|>
13
lolphp
InconsiderateBastard
c5ghk6z
<|sols|><|sot|>Today's PHP-induced bug: arbitrary object properties (PHP fucks me off daily so I've decided to chronicle it)<|eot|><|sol|>http://altreus.blogspot.co.uk/2012/07/todays-php-induced-bug-arbitrary-object.html<|eol|><|sor|>> Point 1 of the two reasons why you don't do what PHP doesn't understand why you don't do is the reason why I wish it didn't. That's the best sentence ever.<|eor|><|eols|><|endoftext|>
7
lolphp
Takeoded
sxt4oz
<|sols|><|sot|>crypt() on failure: return <13 characters of garbage.. makes sense<|eot|><|sol|>https://www.php.net/manual/en/function.crypt<|eol|><|eols|><|endoftext|>
14
lolphp
smegnose
hxu7h2i
<|sols|><|sot|>crypt() on failure: return <13 characters of garbage.. makes sense<|eot|><|sol|>https://www.php.net/manual/en/function.crypt<|eol|><|sor|>Is this another classic u/Takeoded post? So the function is strongly typed, thus guaranteed to be able to be fed into other functions, and will definitely not match the salt alone (to protect people from mistakes using concatenation with common failure return types `false` and `null` that would be cast to the empty string)? Does this mean the following snippet is safe and you think that's bad? if (hash_equals($known_hash, crypt($user_input, $salt_from_known_hash))) { } Also in those docs: >Use of password_hash() is encouraged.<|eor|><|eols|><|endoftext|>
12
lolphp
duskwuff
hxw0173
<|sols|><|sot|>crypt() on failure: return <13 characters of garbage.. makes sense<|eot|><|sol|>https://www.php.net/manual/en/function.crypt<|eol|><|sor|>[deleted]<|eor|><|sor|>That isn't "13 characters of garbage". It's the standard DES hash of `garbage` with the salt `ga` (first two characters of `$salt`), exactly as documented. This is identical to the behavior in the libc implementation of `crypt()`.<|eor|><|eols|><|endoftext|>
11
lolphp
duskwuff
hxzvnqv
<|sols|><|sot|>crypt() on failure: return <13 characters of garbage.. makes sense<|eot|><|sol|>https://www.php.net/manual/en/function.crypt<|eol|><|sor|>Is this another classic u/Takeoded post? So the function is strongly typed, thus guaranteed to be able to be fed into other functions, and will definitely not match the salt alone (to protect people from mistakes using concatenation with common failure return types `false` and `null` that would be cast to the empty string)? Does this mean the following snippet is safe and you think that's bad? if (hash_equals($known_hash, crypt($user_input, $salt_from_known_hash))) { } Also in those docs: >Use of password_hash() is encouraged.<|eor|><|sor|>> Use of password_hash() is encouraged. Which in itself is another lolphp<|eor|><|sor|>>another There has to be a first LOL for there to be a second. And how is it a LOL to offer slightly easier wrapper for noobs, but retain this function from PHP 4?<|eor|><|sor|>> but retain this function from PHP 4? Let's be honest here. PHP didn't invent `crypt()`. It's been part of the C standard library since the 1970s.<|eor|><|eols|><|endoftext|>
6
lolphp
Takeoded
dbenbs
<|soss|><|sot|>(7.4) floats can have default values, but not double<|eot|><|sost|>as of PHP 7.4 (currently in Release Candidate 2, so i don't expect a fix for this prior to release), we can now have typed properties, it looks like this: ```php class C{ public float $f = 0.0; public double $d = 0.0; } ``` ... funny thing is, 1 of those properties have an illegal default value! > Fatal error: Property of type doble may not have default value in /in/GBpuJ on line 6<|eost|><|eoss|><|endoftext|>
12
lolphp
the_alias_of_andrea
f20w0iz
<|soss|><|sot|>(7.4) floats can have default values, but not double<|eot|><|sost|>as of PHP 7.4 (currently in Release Candidate 2, so i don't expect a fix for this prior to release), we can now have typed properties, it looks like this: ```php class C{ public float $f = 0.0; public double $d = 0.0; } ``` ... funny thing is, 1 of those properties have an illegal default value! > Fatal error: Property of type doble may not have default value in /in/GBpuJ on line 6<|eost|><|sor|>`double` is not a scalar type in PHP. You have written a type declaration for a hypothetical class named `double`. Of course a float does not qualify as a valid default value for such a property.<|eor|><|eoss|><|endoftext|>
25
lolphp
Takeoded
f20xi47
<|soss|><|sot|>(7.4) floats can have default values, but not double<|eot|><|sost|>as of PHP 7.4 (currently in Release Candidate 2, so i don't expect a fix for this prior to release), we can now have typed properties, it looks like this: ```php class C{ public float $f = 0.0; public double $d = 0.0; } ``` ... funny thing is, 1 of those properties have an illegal default value! > Fatal error: Property of type doble may not have default value in /in/GBpuJ on line 6<|eost|><|sor|>`double` is not a scalar type in PHP. You have written a type declaration for a hypothetical class named `double`. Of course a float does not qualify as a valid default value for such a property.<|eor|><|soopr|>why the frick does this exist? `(double)val` ? why the frick does `gettype(0.0)` return `double` instead of `float` ? why the frick do we have `doubleval()` ? prior to PHP 7.0, i might have accepted "backwards compatibility", but if that's the only reason, then why weren't they removed in the 7.0.0 release? at some point someone thought it was a good idea to have \`double\` be an alias of \`float\` , but now we have some ***half-assed alias*** where double is an alias \*sometimes\* and not others.. php should make up its mind, either fully support double alias, or not support it at all, instead of this mixed "supported some places and not in other places"<|eoopr|><|eoss|><|endoftext|>
24
lolphp
nikic
f2107pc
<|soss|><|sot|>(7.4) floats can have default values, but not double<|eot|><|sost|>as of PHP 7.4 (currently in Release Candidate 2, so i don't expect a fix for this prior to release), we can now have typed properties, it looks like this: ```php class C{ public float $f = 0.0; public double $d = 0.0; } ``` ... funny thing is, 1 of those properties have an illegal default value! > Fatal error: Property of type doble may not have default value in /in/GBpuJ on line 6<|eost|><|sor|>`double` is not a scalar type in PHP. You have written a type declaration for a hypothetical class named `double`. Of course a float does not qualify as a valid default value for such a property.<|eor|><|soopr|>why the frick does this exist? `(double)val` ? why the frick does `gettype(0.0)` return `double` instead of `float` ? why the frick do we have `doubleval()` ? prior to PHP 7.0, i might have accepted "backwards compatibility", but if that's the only reason, then why weren't they removed in the 7.0.0 release? at some point someone thought it was a good idea to have \`double\` be an alias of \`float\` , but now we have some ***half-assed alias*** where double is an alias \*sometimes\* and not others.. php should make up its mind, either fully support double alias, or not support it at all, instead of this mixed "supported some places and not in other places"<|eoopr|><|sor|>The answer to all your questions is "backwards compatibility" even after PHP 7.0. That said, it might be a good idea to throw a warning when people try to use things like `double` or `integer` as type annotations.<|eor|><|eoss|><|endoftext|>
20
lolphp
Takeoded
f21j95l
<|soss|><|sot|>(7.4) floats can have default values, but not double<|eot|><|sost|>as of PHP 7.4 (currently in Release Candidate 2, so i don't expect a fix for this prior to release), we can now have typed properties, it looks like this: ```php class C{ public float $f = 0.0; public double $d = 0.0; } ``` ... funny thing is, 1 of those properties have an illegal default value! > Fatal error: Property of type doble may not have default value in /in/GBpuJ on line 6<|eost|><|sor|>`double` is not a scalar type in PHP. You have written a type declaration for a hypothetical class named `double`. Of course a float does not qualify as a valid default value for such a property.<|eor|><|soopr|>why the frick does this exist? `(double)val` ? why the frick does `gettype(0.0)` return `double` instead of `float` ? why the frick do we have `doubleval()` ? prior to PHP 7.0, i might have accepted "backwards compatibility", but if that's the only reason, then why weren't they removed in the 7.0.0 release? at some point someone thought it was a good idea to have \`double\` be an alias of \`float\` , but now we have some ***half-assed alias*** where double is an alias \*sometimes\* and not others.. php should make up its mind, either fully support double alias, or not support it at all, instead of this mixed "supported some places and not in other places"<|eoopr|><|sor|>The answer to all your questions is "backwards compatibility" even after PHP 7.0. That said, it might be a good idea to throw a warning when people try to use things like `double` or `integer` as type annotations.<|eor|><|soopr|>7.0 did [lots of BC-breaking changes](https://www.php.net/manual/en/migration70.incompatible.php), this double alias bullshit *\*should\** have been among them<|eoopr|><|sor|>It would be needless breakage, the existing code isn't doing anything wrong, nor standing in the way of serious improvements. We didn't break things just because we felt like it.<|eor|><|soopr|>quote: > Indirect access to variables, properties, and methods will now be evaluated strictly in left-to-right order, as opposed to the previous mix of special cases. The table below shows how the order of evaluation has changed. didn't we fix this because "a mix of special cases" was fking stupid? even tho it broke PHP5 code that actually depends on it? well the double-supported-someplaces is also a mix of (3?) special cases<|eoopr|><|eoss|><|endoftext|>
5
lolphp
the_alias_of_andrea
f224wtb
<|soss|><|sot|>(7.4) floats can have default values, but not double<|eot|><|sost|>as of PHP 7.4 (currently in Release Candidate 2, so i don't expect a fix for this prior to release), we can now have typed properties, it looks like this: ```php class C{ public float $f = 0.0; public double $d = 0.0; } ``` ... funny thing is, 1 of those properties have an illegal default value! > Fatal error: Property of type doble may not have default value in /in/GBpuJ on line 6<|eost|><|sor|>`double` is not a scalar type in PHP. You have written a type declaration for a hypothetical class named `double`. Of course a float does not qualify as a valid default value for such a property.<|eor|><|soopr|>why the frick does this exist? `(double)val` ? why the frick does `gettype(0.0)` return `double` instead of `float` ? why the frick do we have `doubleval()` ? prior to PHP 7.0, i might have accepted "backwards compatibility", but if that's the only reason, then why weren't they removed in the 7.0.0 release? at some point someone thought it was a good idea to have \`double\` be an alias of \`float\` , but now we have some ***half-assed alias*** where double is an alias \*sometimes\* and not others.. php should make up its mind, either fully support double alias, or not support it at all, instead of this mixed "supported some places and not in other places"<|eoopr|><|sor|>The answer to all your questions is "backwards compatibility" even after PHP 7.0. That said, it might be a good idea to throw a warning when people try to use things like `double` or `integer` as type annotations.<|eor|><|soopr|>7.0 did [lots of BC-breaking changes](https://www.php.net/manual/en/migration70.incompatible.php), this double alias bullshit *\*should\** have been among them<|eoopr|><|sor|>It would be needless breakage, the existing code isn't doing anything wrong, nor standing in the way of serious improvements. We didn't break things just because we felt like it.<|eor|><|soopr|>quote: > Indirect access to variables, properties, and methods will now be evaluated strictly in left-to-right order, as opposed to the previous mix of special cases. The table below shows how the order of evaluation has changed. didn't we fix this because "a mix of special cases" was fking stupid? even tho it broke PHP5 code that actually depends on it? well the double-supported-someplaces is also a mix of (3?) special cases<|eoopr|><|sor|>It doesn't hurt anyone that someone's old code uses `doubleval()` instead of `floatval()`. That was not the case for the variable syntax.<|eor|><|eoss|><|endoftext|>
5
lolphp
daxim
d9gpz3
<|sols|><|sot|>No, PHP Doesn't Have Closures<|eot|><|sol|>https://nullprogram.com/blog/2019/09/25/<|eol|><|eols|><|endoftext|>
13
lolphp
PonchoVire
f1h8afc
<|sols|><|sot|>No, PHP Doesn't Have Closures<|eot|><|sol|>https://nullprogram.com/blog/2019/09/25/<|eol|><|soopr|> <?php function bar($n) { $f = function() use ($n) { return $n; }; $n++; return $f; } var_dump(bar(1)()); // int(1) ---- #!/usr/bin/env node function bar(n) { let f = function() { return n; }; n++; return f; } console.log(bar(1)()); // 2 ---- #!/usr/bin/env perl use 5.010; use strict; use warnings; sub bar { my ($n) = @_; my $f = sub { return $n; }; $n++; return $f; } say bar(1)->(); # 2 ---- #!/usr/bin/env python3 def bar(n): f = lambda: n n += 1 return f print(bar(1)()) # 2<|eoopr|><|sor|>Note that if you close the variable using a reference (ie. `&`) it works. It's just a question of semantics. In the end, it's a real closure, it's just more verbose. ``` <?php function bar($n) { $f = function() use (&$n) { return $n; }; $n++; return $f; } var_dump(bar(1)()); // int(2)<|eor|><|eols|><|endoftext|>
14
lolphp
jesseschalken
f1id4nu
<|sols|><|sot|>No, PHP Doesn't Have Closures<|eot|><|sol|>https://nullprogram.com/blog/2019/09/25/<|eol|><|sor|>Where did he get the idea that a closure isn't a closure unless it captures the variable by reference? He seems to have just made that up. If it were true, Haskell, Ocaml and even C++ wouldn't have closures, and they obviously do.<|eor|><|eols|><|endoftext|>
10
lolphp
daxim
f1h5r0g
<|sols|><|sot|>No, PHP Doesn't Have Closures<|eot|><|sol|>https://nullprogram.com/blog/2019/09/25/<|eol|><|soopr|> <?php function bar($n) { $f = function() use ($n) { return $n; }; $n++; return $f; } var_dump(bar(1)()); // int(1) ---- #!/usr/bin/env node function bar(n) { let f = function() { return n; }; n++; return f; } console.log(bar(1)()); // 2 ---- #!/usr/bin/env perl use 5.010; use strict; use warnings; sub bar { my ($n) = @_; my $f = sub { return $n; }; $n++; return $f; } say bar(1)->(); # 2 ---- #!/usr/bin/env python3 def bar(n): f = lambda: n n += 1 return f print(bar(1)()) # 2<|eoopr|><|eols|><|endoftext|>
5
lolphp
daxim
f1hayor
<|sols|><|sot|>No, PHP Doesn't Have Closures<|eot|><|sol|>https://nullprogram.com/blog/2019/09/25/<|eol|><|soopr|> <?php function bar($n) { $f = function() use ($n) { return $n; }; $n++; return $f; } var_dump(bar(1)()); // int(1) ---- #!/usr/bin/env node function bar(n) { let f = function() { return n; }; n++; return f; } console.log(bar(1)()); // 2 ---- #!/usr/bin/env perl use 5.010; use strict; use warnings; sub bar { my ($n) = @_; my $f = sub { return $n; }; $n++; return $f; } say bar(1)->(); # 2 ---- #!/usr/bin/env python3 def bar(n): f = lambda: n n += 1 return f print(bar(1)()) # 2<|eoopr|><|sor|>Note that if you close the variable using a reference (ie. `&`) it works. It's just a question of semantics. In the end, it's a real closure, it's just more verbose. ``` <?php function bar($n) { $f = function() use (&$n) { return $n; }; $n++; return $f; } var_dump(bar(1)()); // int(2)<|eor|><|soopr|>Somehow I'm now more upset than when I assumed it didn't work at all.<|eoopr|><|eols|><|endoftext|>
5
lolphp
dzuczek
d0hwoa
<|soss|><|sot|>timewarps to the year 2001<|eot|><|sost|>// 1 BC php > print date('Y-m-d', mktime(0, 0, 0, 2, 21, -1)); -0001-02-21 // 1 AD php > print date('Y-m-d', mktime(0, 0, 0, 2, 21, 1)); 2001-02-21<|eost|><|eoss|><|endoftext|>
13
lolphp
the_alias_of_andrea
ezam92p
<|soss|><|sot|>timewarps to the year 2001<|eot|><|sost|>// 1 BC php > print date('Y-m-d', mktime(0, 0, 0, 2, 21, -1)); -0001-02-21 // 1 AD php > print date('Y-m-d', mktime(0, 0, 0, 2, 21, 1)); 2001-02-21<|eost|><|sor|>[deleted]<|eor|><|sor|>> Javascript, which has the same syntax for that, treats this as a number with base of 10. I think that's much worse. It means [ 008, 009, 010, 011 ] silently evaluates to `[ 8, 9, 8, 9 ]`.<|eor|><|sor|>Oh, it used to be worse, PHP evaluated it as `[ 0, 0, 8, 9 ]`. I fixed it :D<|eor|><|eoss|><|endoftext|>
12
lolphp
barubary
eza43nj
<|soss|><|sot|>timewarps to the year 2001<|eot|><|sost|>// 1 BC php > print date('Y-m-d', mktime(0, 0, 0, 2, 21, -1)); -0001-02-21 // 1 AD php > print date('Y-m-d', mktime(0, 0, 0, 2, 21, 1)); 2001-02-21<|eost|><|sor|>[deleted]<|eor|><|sor|>> Javascript, which has the same syntax for that, treats this as a number with base of 10. I think that's much worse. It means [ 008, 009, 010, 011 ] silently evaluates to `[ 8, 9, 8, 9 ]`.<|eor|><|eoss|><|endoftext|>
11
lolphp
pilif
740deb
<|sols|><|sot|>SplFileInfo->current() has side-effects. ->valid() will never be false until you call ->current()<|eot|><|sol|>https://3v4l.org/W0rL2<|eol|><|eols|><|endoftext|>
14
lolphp
maweki
dnuhteo
<|sols|><|sot|>SplFileInfo->current() has side-effects. ->valid() will never be false until you call ->current()<|eot|><|sol|>https://3v4l.org/W0rL2<|eol|><|sor|>It's not about the side effects. About everything moves the read-pointer. valid checks for EOF which is unknown until something is read. The real WTF here is that next() does nothing if you're not at the end of the line and current() reads the current line but doesn't advance you to the next. That is a strange and undocumented (albeit discussed) behaviour.<|eor|><|eols|><|endoftext|>
9
lolphp
h4l
41ejnm
<|sols|><|sot|>PHP debugger XDebug can't break on or step into single-line conditional blocks (without braces) due to the way PHP assigns line numbers to its bytecode<|eot|><|sol|>http://bugs.xdebug.org/view.php?id=842<|eol|><|eols|><|endoftext|>
13
lolphp
the_alias_of_andrea
cz1rv29
<|sols|><|sot|>PHP debugger XDebug can't break on or step into single-line conditional blocks (without braces) due to the way PHP assigns line numbers to its bytecode<|eot|><|sol|>http://bugs.xdebug.org/view.php?id=842<|eol|><|sor|>Yes, PHP has bugs. This is from three and a half years ago, before the PHP compiler was rewritten for the abstract syntax tree in PHP 7, heck, it's before 5.5 and 5.6. I dare say it may have been fixed since. Let's test it out shall we? Here's some code: <?php if ($cond) doThis(); else doThat(); Now let's open it in `phpdbg` and see what the opcodes look like: $ sapi/phpdbg/phpdbg foobar.php [Welcome to phpdbg, the interactive PHP debugger, v0.5.0] To get help using phpdbg type "help" and press enter [Please report bugs to <http://bugs.php.net/report.php>] [Successful compilation of /Users/ajf/Projects/2014/PHP/php-src/foobar.php] prompt> run [Uncaught Error in /Users/ajf/Projects/2014/PHP/php-src/foobar.php on line 5: Call to undefined function doThat()] >00005: doThat(); 00006: prompt> print [Stack in /Users/ajf/Projects/2014/PHP/php-src/foobar.php (7 ops)] L1-5 {main}() /Users/ajf/Projects/2014/PHP/php-src/foobar.php - 0x104e67500 + 7 ops L2 #0 JMPZ $cond J4 L3 #1 INIT_FCALL_BY_NAME "doThis" L3 #2 DO_FCALL L3 #3 JMP J6 L5 #4 INIT_FCALL_BY_NAME "doThat" L5 #5 DO_FCALL L5 #6 RETURN 1 Oh look, it assigns opcodes correctly now. :) So, the "lolphp" here is that PHP had a bug, and it was fixed? Fixing bugs is bad, kids. Don't do that.<|eor|><|eols|><|endoftext|>
22
lolphp
the_alias_of_andrea
cz1y4a5
<|sols|><|sot|>PHP debugger XDebug can't break on or step into single-line conditional blocks (without braces) due to the way PHP assigns line numbers to its bytecode<|eot|><|sol|>http://bugs.xdebug.org/view.php?id=842<|eol|><|sor|>Yes, PHP has bugs. This is from three and a half years ago, before the PHP compiler was rewritten for the abstract syntax tree in PHP 7, heck, it's before 5.5 and 5.6. I dare say it may have been fixed since. Let's test it out shall we? Here's some code: <?php if ($cond) doThis(); else doThat(); Now let's open it in `phpdbg` and see what the opcodes look like: $ sapi/phpdbg/phpdbg foobar.php [Welcome to phpdbg, the interactive PHP debugger, v0.5.0] To get help using phpdbg type "help" and press enter [Please report bugs to <http://bugs.php.net/report.php>] [Successful compilation of /Users/ajf/Projects/2014/PHP/php-src/foobar.php] prompt> run [Uncaught Error in /Users/ajf/Projects/2014/PHP/php-src/foobar.php on line 5: Call to undefined function doThat()] >00005: doThat(); 00006: prompt> print [Stack in /Users/ajf/Projects/2014/PHP/php-src/foobar.php (7 ops)] L1-5 {main}() /Users/ajf/Projects/2014/PHP/php-src/foobar.php - 0x104e67500 + 7 ops L2 #0 JMPZ $cond J4 L3 #1 INIT_FCALL_BY_NAME "doThis" L3 #2 DO_FCALL L3 #3 JMP J6 L5 #4 INIT_FCALL_BY_NAME "doThat" L5 #5 DO_FCALL L5 #6 RETURN 1 Oh look, it assigns opcodes correctly now. :) So, the "lolphp" here is that PHP had a bug, and it was fixed? Fixing bugs is bad, kids. Don't do that.<|eor|><|sor|>This is /r/lolphp, not /r/lolphp7.<|eor|><|sor|>PHP 7 isn't a different language, just a newer iteration, and anyway [the bug has also been fixed in PHP 5](https://3v4l.org/E4b4T/vld#tabs).<|eor|><|eols|><|endoftext|>
5
lolphp
Max-P
2ktoz5
<|sols|><|sot|>htmlentities can convert accentuated characters, but only if the user typed it in the correct way ( ~= &agrave)<|eot|><|sol|>http://3v4l.org/Ftoto<|eol|><|eols|><|endoftext|>
11
lolphp
allthediamonds
clolr6s
<|sols|><|sot|>htmlentities can convert accentuated characters, but only if the user typed it in the correct way ( ~= &agrave)<|eot|><|sol|>http://3v4l.org/Ftoto<|eol|><|sor|>Is there a single function on the PHP standard library that **isn't** a bug waiting to happen?<|eor|><|eols|><|endoftext|>
12
lolphp
Scaliwag
cloobfh
<|sols|><|sot|>htmlentities can convert accentuated characters, but only if the user typed it in the correct way ( ~= &agrave)<|eot|><|sol|>http://3v4l.org/Ftoto<|eol|><|soopr|>To be really extra fair, I didn't know the same character could be encoded differently either until it blew up on me today. htmlentities probably is just a big str_replace with all possibly known characters and their HTML entity equivalent hardcoded in the source code... This is from a **file name** uploaded by a user. My app and web server are all UTF-8 all the way so it used to work just fine until I hit that particular one over a year after I last touched this code. The image loads fine, but not on all browsers. I threw in an htmlentities() as a desperate attempt at fixing it and noticed only half the accentuated characters converted properly in the URL and that still didn't solve the problem. urlencode() doesn't like it either.<|eoopr|><|sor|>[You're spot on they use a hash table to do the look-ups.](https://github.com/php/php-src/blob/88ca46d92bc1c426e7c7f7313f0fd2b7dcc33cf6/ext/standard/html.c#L856) ---- While looking for it I found [this awesome use of goto to go back from the a nested else back into the if part. :-)](https://github.com/php/php-src/blob/88ca46d92bc1c426e7c7f7313f0fd2b7dcc33cf6/ext/standard/html.c#L1414) <|eor|><|eols|><|endoftext|>
9
lolphp
Rhomboid
clpe5na
<|sols|><|sot|>htmlentities can convert accentuated characters, but only if the user typed it in the correct way ( ~= &agrave)<|eot|><|sol|>http://3v4l.org/Ftoto<|eol|><|sor|>What's the correct way? I'm not getting it. <|eor|><|sor|>The first is the precomposed form: U+00E0 (LATIN SMALL LETTER A WITH GRAVE). The second a uses a combining diacritical mark: U+0061 (LATIN SMALL LETTER A) followed by U+0300 (COMBINING GRAVE ACCENT). This kind of discrepancy is why Unicode specifies normalization rules; you'd get the former with Normalization Form C (NFC), the latter with Normalization Form D (NFD). A properly implemented system would probably, at the very minimum, first normalize the entire string and then perform the replacements based on the chosen normalization form. But of course this is PHP so just hack something together that appears to work and call it a day. <|eor|><|eols|><|endoftext|>
8
lolphp
allthediamonds
cloosti
<|sols|><|sot|>htmlentities can convert accentuated characters, but only if the user typed it in the correct way ( ~= &agrave)<|eot|><|sol|>http://3v4l.org/Ftoto<|eol|><|soopr|>To be really extra fair, I didn't know the same character could be encoded differently either until it blew up on me today. htmlentities probably is just a big str_replace with all possibly known characters and their HTML entity equivalent hardcoded in the source code... This is from a **file name** uploaded by a user. My app and web server are all UTF-8 all the way so it used to work just fine until I hit that particular one over a year after I last touched this code. The image loads fine, but not on all browsers. I threw in an htmlentities() as a desperate attempt at fixing it and noticed only half the accentuated characters converted properly in the URL and that still didn't solve the problem. urlencode() doesn't like it either.<|eoopr|><|sor|>I'm not an Unicode expert by any means, but I think this would be fixed by normalizing Unicode codepoints and having unknown Unicode characters default to numeric HTML entity references.<|eor|><|eols|><|endoftext|>
6
lolphp
TheGreatFohl
2jxgcg
<|sols|><|sot|>array_unique and objects => *boom*<|eot|><|sol|>http://3v4l.org/jABl1<|eol|><|eols|><|endoftext|>
13
lolphp
allthediamonds
clgdjov
<|sols|><|sot|>array_unique and objects => *boom*<|eot|><|sol|>http://3v4l.org/jABl1<|eol|><|soopr|>Because [array_unique](http://php.net/manual/en/function.array-unique.php) converts everything to strings to sort it. Obviously you need to use the SORT_REGULAR flag which is, logically, not the default option. EDIT: I also just realized that in PHP 5.2.9 SORT_REGULAR was in fact the default value (that version is when the flag was introduced). Apparently it got changed to SORT_STRING in the next version (most likely because of some backwards incompatibility).<|eoopr|><|sor|>and it's the language's fault that you can't read a function definition?<|eor|><|sor|>We can read it just fine. It's the language's fault that we have to, because every function has seven potential gotchas in it.<|eor|><|eols|><|endoftext|>
16
lolphp
x3al
clgbozm
<|sols|><|sot|>array_unique and objects => *boom*<|eot|><|sol|>http://3v4l.org/jABl1<|eol|><|soopr|>Because [array_unique](http://php.net/manual/en/function.array-unique.php) converts everything to strings to sort it. Obviously you need to use the SORT_REGULAR flag which is, logically, not the default option. EDIT: I also just realized that in PHP 5.2.9 SORT_REGULAR was in fact the default value (that version is when the flag was introduced). Apparently it got changed to SORT_STRING in the next version (most likely because of some backwards incompatibility).<|eoopr|><|sor|>and it's the language's fault that you can't read a function definition?<|eor|><|sor|>This language forces to read a definition for each function you want to use. <|eor|><|eols|><|endoftext|>
13
lolphp
willglynn
clgi5z4
<|sols|><|sot|>array_unique and objects => *boom*<|eot|><|sol|>http://3v4l.org/jABl1<|eol|><|sor|>I enjoyed [the changelog](http://php.net/manual/en/function.array-unique.php#refsect1-function.array-unique-changelog): > ## Changelog > > > > Version | Description > ---|--- > 5.2.10 | Changed the default value of `sort_flags` back to `SORT_STRING`. > 5.2.9 | Added the optional `sort_flags` defaulting to `SORT_REGULAR`. Prior to 5.2.9, this function used to sort the array with `SORT_STRING` internally. This leads to additional humor in the form of [bug #47370](https://bugs.php.net/bug.php?id=47370): > It is because `SORT_REGULAR` never cast array elements and compares them with `==`. I think it's better for `SORT_REGULAR` to compare elements by using `===` instead of `==`. > > > > Thank you for taking the time to write to us, but this is not a bug. The slight BC breakage is negligible compared to the benefits of getting it to work properly. > > > > The array `$a` and `$b` have same 3 elements with different ordering. Although, two `array_unique()` returns different result. > First `array_unique()` returns 3 elements in spite of the fact that `"10"` equals `"1e1"` with `==`. > > In fact, the two arrays are both sorted about `SORT_REGULAR`. Because `"10" < "1az"`, `"1az" < "1e1"` and `"1e1"=="10"`. Sorting with `SORT_REGULAR` is not stable, and unique element is not always in neighbor. > > This is definitely BC break in 5.2.9 as comparing `'400.000'` and `'400'` in `array_unique` in PHP versions prior 5.2.9 returned both values. In PHP 5.2.9 it return `'400.000'`. Finally, [bug #65208](https://bugs.php.net/bug.php?id=65208) proposes adding `SORT_STRICT` for anyone who wants a type-safe uniqueness mode that uses the `===` type-safe equivalence operator. This is what a nave person might expect `SORT_REGULAR` to do, and naturally, it remains a proposal. (edit: formatting)<|eor|><|eols|><|endoftext|>
12
lolphp
TheGreatFohl
clgdus6
<|sols|><|sot|>array_unique and objects => *boom*<|eot|><|sol|>http://3v4l.org/jABl1<|eol|><|soopr|>Because [array_unique](http://php.net/manual/en/function.array-unique.php) converts everything to strings to sort it. Obviously you need to use the SORT_REGULAR flag which is, logically, not the default option. EDIT: I also just realized that in PHP 5.2.9 SORT_REGULAR was in fact the default value (that version is when the flag was introduced). Apparently it got changed to SORT_STRING in the next version (most likely because of some backwards incompatibility).<|eoopr|><|sor|>and it's the language's fault that you can't read a function definition?<|eor|><|soopr|>I'm mostly questioning why the default flag is SORT_STRING, when everything in the manual points to the fact that SORT_REGULAR should really be the default. It's called /regular/ even and the description says "compare items normally". Why is doing things the regular and normal way not the default? Instead I have to deal with these error reports.<|eoopr|><|eols|><|endoftext|>
9
lolphp
TheGreatFohl
clfyaig
<|sols|><|sot|>array_unique and objects => *boom*<|eot|><|sol|>http://3v4l.org/jABl1<|eol|><|soopr|>Because [array_unique](http://php.net/manual/en/function.array-unique.php) converts everything to strings to sort it. Obviously you need to use the SORT_REGULAR flag which is, logically, not the default option. EDIT: I also just realized that in PHP 5.2.9 SORT_REGULAR was in fact the default value (that version is when the flag was introduced). Apparently it got changed to SORT_STRING in the next version (most likely because of some backwards incompatibility).<|eoopr|><|eols|><|endoftext|>
6
lolphp
krinndnz
120r50
<|sols|><|sot|>A comment thread about WPEngine issues becomes about WordPress' horrible architecture<|eot|><|sol|>http://news.ycombinator.com/item?id=4692456<|eol|><|eols|><|endoftext|>
11
lolphp
infinull
c6rcwkn
<|sols|><|sot|>A comment thread about WPEngine issues becomes about WordPress' horrible architecture<|eot|><|sol|>http://news.ycombinator.com/item?id=4692456<|eol|><|sor|>I know it's trendy to bash PHP, but you can write elegant, well-performing code in PHP. Of course, Wordpress doesn't do that...<|eor|><|sor|>Well yes, it's trendy to bash PHP in a subreddit devoted to bashing PHP. Did you forget that you had subscribed?<|eor|><|sor|>I was just pointing out that WP's lack of architecture is not really a reflection on how bad (or good) PHP itself is. So this should be in /r/lolwordpress not /r/lolphp.<|eor|><|sor|>I've discussed this before, but this sub has clearly spread to be /r/lolphpecosystem more than just /r/lolphp which I find to be fine.<|eor|><|eols|><|endoftext|>
11
lolphp
SirClueless
c6rb92z
<|sols|><|sot|>A comment thread about WPEngine issues becomes about WordPress' horrible architecture<|eot|><|sol|>http://news.ycombinator.com/item?id=4692456<|eol|><|sor|>I know it's trendy to bash PHP, but you can write elegant, well-performing code in PHP. Of course, Wordpress doesn't do that...<|eor|><|sor|>Well yes, it's trendy to bash PHP in a subreddit devoted to bashing PHP. Did you forget that you had subscribed?<|eor|><|eols|><|endoftext|>
9
lolphp
krinndnz
c6rfvem
<|sols|><|sot|>A comment thread about WPEngine issues becomes about WordPress' horrible architecture<|eot|><|sol|>http://news.ycombinator.com/item?id=4692456<|eol|><|sor|>I know it's trendy to bash PHP, but you can write elegant, well-performing code in PHP. Of course, Wordpress doesn't do that...<|eor|><|sor|>Well yes, it's trendy to bash PHP in a subreddit devoted to bashing PHP. Did you forget that you had subscribed?<|eor|><|sor|>I was just pointing out that WP's lack of architecture is not really a reflection on how bad (or good) PHP itself is. So this should be in /r/lolwordpress not /r/lolphp.<|eor|><|sor|>I've discussed this before, but this sub has clearly spread to be /r/lolphpecosystem more than just /r/lolphp which I find to be fine.<|eor|><|soopr|>That was the sense in which I posted it - that and "behold, no castle worth defending can be built upon foundations of sand and mud."<|eoopr|><|eols|><|endoftext|>
8
lolphp
David_Crockett
c6rbess
<|sols|><|sot|>A comment thread about WPEngine issues becomes about WordPress' horrible architecture<|eot|><|sol|>http://news.ycombinator.com/item?id=4692456<|eol|><|sor|>I know it's trendy to bash PHP, but you can write elegant, well-performing code in PHP. Of course, Wordpress doesn't do that...<|eor|><|sor|>Well yes, it's trendy to bash PHP in a subreddit devoted to bashing PHP. Did you forget that you had subscribed?<|eor|><|sor|>I was just pointing out that WP's lack of architecture is not really a reflection on how bad (or good) PHP itself is. So this should be in /r/lolwordpress not /r/lolphp.<|eor|><|eols|><|endoftext|>
7
lolphp
David_Crockett
c6r9hag
<|sols|><|sot|>A comment thread about WPEngine issues becomes about WordPress' horrible architecture<|eot|><|sol|>http://news.ycombinator.com/item?id=4692456<|eol|><|sor|>I know it's trendy to bash PHP, but you can write elegant, well-performing code in PHP. Of course, Wordpress doesn't do that...<|eor|><|eols|><|endoftext|>
5
lolphp
midir
xiz20
<|soss|><|sot|>Things which PHP thinks are equal<|eot|><|sost|>Give it a go: header('Content-Type: text/plain'); function test($a, $b) { echo var_export($a, 1) . ' == ' . var_export($b, 1) . ' => ' . var_export($a == $b, 1) . "\n"; } test( null, '' ); // true test( null, array() ); // true test( '', array() ); // false test( 'true', true ); // true test( 'false', false ); // false test( 'false', true ); // true test( 9, '09' ); // true test( 9, 09 ); // false test( '0E4', 09 ); // true test( '0x00', '0E4' ); // true test( '0x0.1', 0 ); // true test( 'x', 0 ); // true test( '0xabcabcabcabcabc', '0XABCABCABCABCABd' ); // true test( array('1'), array('0x1') ); // true test( array(1) + array(2), array(1) ); // true test( function(){}, new stdclass() ); // true test( `foo`, `bar` ); // true <|eost|><|eoss|><|endoftext|>
14
lolphp
poizan42
c5oytml
<|soss|><|sot|>Things which PHP thinks are equal<|eot|><|sost|>Give it a go: header('Content-Type: text/plain'); function test($a, $b) { echo var_export($a, 1) . ' == ' . var_export($b, 1) . ' => ' . var_export($a == $b, 1) . "\n"; } test( null, '' ); // true test( null, array() ); // true test( '', array() ); // false test( 'true', true ); // true test( 'false', false ); // false test( 'false', true ); // true test( 9, '09' ); // true test( 9, 09 ); // false test( '0E4', 09 ); // true test( '0x00', '0E4' ); // true test( '0x0.1', 0 ); // true test( 'x', 0 ); // true test( '0xabcabcabcabcabc', '0XABCABCABCABCABd' ); // true test( array('1'), array('0x1') ); // true test( array(1) + array(2), array(1) ); // true test( function(){}, new stdclass() ); // true test( `foo`, `bar` ); // true <|eost|><|sor|>Moral of the story: develop like == and != doesn't exists.<|eor|><|eoss|><|endoftext|>
7
lolphp
Denommus
c5r2lst
<|soss|><|sot|>Things which PHP thinks are equal<|eot|><|sost|>Give it a go: header('Content-Type: text/plain'); function test($a, $b) { echo var_export($a, 1) . ' == ' . var_export($b, 1) . ' => ' . var_export($a == $b, 1) . "\n"; } test( null, '' ); // true test( null, array() ); // true test( '', array() ); // false test( 'true', true ); // true test( 'false', false ); // false test( 'false', true ); // true test( 9, '09' ); // true test( 9, 09 ); // false test( '0E4', 09 ); // true test( '0x00', '0E4' ); // true test( '0x0.1', 0 ); // true test( 'x', 0 ); // true test( '0xabcabcabcabcabc', '0XABCABCABCABCABd' ); // true test( array('1'), array('0x1') ); // true test( array(1) + array(2), array(1) ); // true test( function(){}, new stdclass() ); // true test( `foo`, `bar` ); // true <|eost|><|sor|>A bunch of these actually make sense, and some will work in more sane languages as well. The lesson to take away from this is that you shouldn't rely on type coercion always do what you expect.<|eor|><|sor|>Testing in ruby false false false false false false false SyntaxError: (eval):2: Invalid octal digit SyntaxError: (eval):2: Invalid octal digit false false false false TypeError: can't convert String into Integer false false I don't know what (`) means in PHP, so I can't test the last one.<|eor|><|eoss|><|endoftext|>
6
lolphp
JAPH
c5p2fa2
<|soss|><|sot|>Things which PHP thinks are equal<|eot|><|sost|>Give it a go: header('Content-Type: text/plain'); function test($a, $b) { echo var_export($a, 1) . ' == ' . var_export($b, 1) . ' => ' . var_export($a == $b, 1) . "\n"; } test( null, '' ); // true test( null, array() ); // true test( '', array() ); // false test( 'true', true ); // true test( 'false', false ); // false test( 'false', true ); // true test( 9, '09' ); // true test( 9, 09 ); // false test( '0E4', 09 ); // true test( '0x00', '0E4' ); // true test( '0x0.1', 0 ); // true test( 'x', 0 ); // true test( '0xabcabcabcabcabc', '0XABCABCABCABCABd' ); // true test( array('1'), array('0x1') ); // true test( array(1) + array(2), array(1) ); // true test( function(){}, new stdclass() ); // true test( `foo`, `bar` ); // true <|eost|><|sor|>A bunch of these actually make sense, and some will work in more sane languages as well. The lesson to take away from this is that you shouldn't rely on type coercion always do what you expect.<|eor|><|eoss|><|endoftext|>
5
lolphp
midir
c5sysax
<|soss|><|sot|>Things which PHP thinks are equal<|eot|><|sost|>Give it a go: header('Content-Type: text/plain'); function test($a, $b) { echo var_export($a, 1) . ' == ' . var_export($b, 1) . ' => ' . var_export($a == $b, 1) . "\n"; } test( null, '' ); // true test( null, array() ); // true test( '', array() ); // false test( 'true', true ); // true test( 'false', false ); // false test( 'false', true ); // true test( 9, '09' ); // true test( 9, 09 ); // false test( '0E4', 09 ); // true test( '0x00', '0E4' ); // true test( '0x0.1', 0 ); // true test( 'x', 0 ); // true test( '0xabcabcabcabcabc', '0XABCABCABCABCABd' ); // true test( array('1'), array('0x1') ); // true test( array(1) + array(2), array(1) ); // true test( function(){}, new stdclass() ); // true test( `foo`, `bar` ); // true <|eost|><|sor|>Moral of the story: develop like == and != doesn't exists.<|eor|><|soopr|>That doesn't solve similar problems with `>`, `>=`, `<`, and `<=`.<|eoopr|><|eoss|><|endoftext|>
5
lolphp
barubary
d9kucp
<|soss|><|sot|>-2 squared is -4<|eot|><|sost|>[Floating point numbers](https://www.php.net/manual/en/language.types.float.php), quoth the manual: > Formally: > LNUM [0-9]+ > DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*) > EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM}) In other words, a floating-point literal using exponential notation is a token consisting of the following parts: - a sign (optional) - the significand, a non-empty sequence of digits, optionally containing a `.` somewhere - the exponent marker, `e` or `E` - another sign (optional) - the exponent, a non-empty sequence of digits For example, `-2e0` is a floating-point literal in this format. Its value is -2. What happens when we square it? <?php echo -2e0, "\n"; echo -2e0 ** 2, "\n"; That's right, we get -4: -2 -4 ([Live demo](https://3v4l.org/AGgLo))<|eost|><|eoss|><|endoftext|>
13
lolphp
shinmai_rookie
f1ihls2
<|soss|><|sot|>-2 squared is -4<|eot|><|sost|>[Floating point numbers](https://www.php.net/manual/en/language.types.float.php), quoth the manual: > Formally: > LNUM [0-9]+ > DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*) > EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM}) In other words, a floating-point literal using exponential notation is a token consisting of the following parts: - a sign (optional) - the significand, a non-empty sequence of digits, optionally containing a `.` somewhere - the exponent marker, `e` or `E` - another sign (optional) - the exponent, a non-empty sequence of digits For example, `-2e0` is a floating-point literal in this format. Its value is -2. What happens when we square it? <?php echo -2e0, "\n"; echo -2e0 ** 2, "\n"; That's right, we get -4: -2 -4 ([Live demo](https://3v4l.org/AGgLo))<|eost|><|sor|>But if memory holds exponentiation also has bigger priority than negation in *normal* mathematics, so this is the expected behavior.<|eor|><|eoss|><|endoftext|>
20
lolphp
barubary
f1imai5
<|soss|><|sot|>-2 squared is -4<|eot|><|sost|>[Floating point numbers](https://www.php.net/manual/en/language.types.float.php), quoth the manual: > Formally: > LNUM [0-9]+ > DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*) > EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM}) In other words, a floating-point literal using exponential notation is a token consisting of the following parts: - a sign (optional) - the significand, a non-empty sequence of digits, optionally containing a `.` somewhere - the exponent marker, `e` or `E` - another sign (optional) - the exponent, a non-empty sequence of digits For example, `-2e0` is a floating-point literal in this format. Its value is -2. What happens when we square it? <?php echo -2e0, "\n"; echo -2e0 ** 2, "\n"; That's right, we get -4: -2 -4 ([Live demo](https://3v4l.org/AGgLo))<|eost|><|sor|>That's because for some reason it evaluates the `**` operation *before* taking the `-` into consideration. Assign `-2e0` (or just `-2` for that matter) to a variable or add parentheses and the problem is gone. The same thing happens in Python: Python 3.7.4 (default, Jul 16 2019, 07:12:58) [GCC 9.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> -2 ** 2 -4 >>> (-2) ** 2 4 Interestingly enough, JavaScript *does* complain. Welcome to Node.js v12.10.0. Type ".help" for more information. > -2 ** 2 Thrown: -2 ** 2 ^^^^^ SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence Not sure what's going on here but my guess is that there's a clever explanation and it's not PHP's fault this time.<|eor|><|soopr|>The behavior is "correct". What's going on here is that unary `-` and `**` are separate operators and `**` has higher precedence. However, what's not correct is the documentation which painstakingly uses EBNF syntax to clarify that the leading `-` sign is part of the number literal, which is just not the case. Why do they even bother with formal notation if the content is wrong? That is the lolphp.<|eoopr|><|eoss|><|endoftext|>
18
lolphp
shinmai_rookie
f1ija2e
<|soss|><|sot|>-2 squared is -4<|eot|><|sost|>[Floating point numbers](https://www.php.net/manual/en/language.types.float.php), quoth the manual: > Formally: > LNUM [0-9]+ > DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*) > EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM}) In other words, a floating-point literal using exponential notation is a token consisting of the following parts: - a sign (optional) - the significand, a non-empty sequence of digits, optionally containing a `.` somewhere - the exponent marker, `e` or `E` - another sign (optional) - the exponent, a non-empty sequence of digits For example, `-2e0` is a floating-point literal in this format. Its value is -2. What happens when we square it? <?php echo -2e0, "\n"; echo -2e0 ** 2, "\n"; That's right, we get -4: -2 -4 ([Live demo](https://3v4l.org/AGgLo))<|eost|><|sor|>That's because for some reason it evaluates the `**` operation *before* taking the `-` into consideration. Assign `-2e0` (or just `-2` for that matter) to a variable or add parentheses and the problem is gone. The same thing happens in Python: Python 3.7.4 (default, Jul 16 2019, 07:12:58) [GCC 9.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> -2 ** 2 -4 >>> (-2) ** 2 4 Interestingly enough, JavaScript *does* complain. Welcome to Node.js v12.10.0. Type ".help" for more information. > -2 ** 2 Thrown: -2 ** 2 ^^^^^ SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence Not sure what's going on here but my guess is that there's a clever explanation and it's not PHP's fault this time.<|eor|><|sor|>>Not sure what's going on here but my guess is that there's a clever explanation and it's not PHP's fault this time. Unless I'm missing something, in mathematics -2^2 is equivalent to -(2^(2)), and different from (-2)^(2), so even if this is incoherent with some inner aspect of PHP, it's definitely coherent with common usage.<|eor|><|eoss|><|endoftext|>
12
lolphp
Retzudo
f1iipbe
<|soss|><|sot|>-2 squared is -4<|eot|><|sost|>[Floating point numbers](https://www.php.net/manual/en/language.types.float.php), quoth the manual: > Formally: > LNUM [0-9]+ > DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*) > EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM}) In other words, a floating-point literal using exponential notation is a token consisting of the following parts: - a sign (optional) - the significand, a non-empty sequence of digits, optionally containing a `.` somewhere - the exponent marker, `e` or `E` - another sign (optional) - the exponent, a non-empty sequence of digits For example, `-2e0` is a floating-point literal in this format. Its value is -2. What happens when we square it? <?php echo -2e0, "\n"; echo -2e0 ** 2, "\n"; That's right, we get -4: -2 -4 ([Live demo](https://3v4l.org/AGgLo))<|eost|><|sor|>That's because for some reason it evaluates the `**` operation *before* taking the `-` into consideration. Assign `-2e0` (or just `-2` for that matter) to a variable or add parentheses and the problem is gone. The same thing happens in Python: Python 3.7.4 (default, Jul 16 2019, 07:12:58) [GCC 9.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> -2 ** 2 -4 >>> (-2) ** 2 4 Interestingly enough, JavaScript *does* complain. Welcome to Node.js v12.10.0. Type ".help" for more information. > -2 ** 2 Thrown: -2 ** 2 ^^^^^ SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence Not sure what's going on here but my guess is that there's a clever explanation and it's not PHP's fault this time.<|eor|><|eoss|><|endoftext|>
7
lolphp
barubary
f1jhpen
<|soss|><|sot|>-2 squared is -4<|eot|><|sost|>[Floating point numbers](https://www.php.net/manual/en/language.types.float.php), quoth the manual: > Formally: > LNUM [0-9]+ > DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*) > EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM}) In other words, a floating-point literal using exponential notation is a token consisting of the following parts: - a sign (optional) - the significand, a non-empty sequence of digits, optionally containing a `.` somewhere - the exponent marker, `e` or `E` - another sign (optional) - the exponent, a non-empty sequence of digits For example, `-2e0` is a floating-point literal in this format. Its value is -2. What happens when we square it? <?php echo -2e0, "\n"; echo -2e0 ** 2, "\n"; That's right, we get -4: -2 -4 ([Live demo](https://3v4l.org/AGgLo))<|eost|><|sor|>That's because for some reason it evaluates the `**` operation *before* taking the `-` into consideration. Assign `-2e0` (or just `-2` for that matter) to a variable or add parentheses and the problem is gone. The same thing happens in Python: Python 3.7.4 (default, Jul 16 2019, 07:12:58) [GCC 9.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> -2 ** 2 -4 >>> (-2) ** 2 4 Interestingly enough, JavaScript *does* complain. Welcome to Node.js v12.10.0. Type ".help" for more information. > -2 ** 2 Thrown: -2 ** 2 ^^^^^ SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence Not sure what's going on here but my guess is that there's a clever explanation and it's not PHP's fault this time.<|eor|><|soopr|>The behavior is "correct". What's going on here is that unary `-` and `**` are separate operators and `**` has higher precedence. However, what's not correct is the documentation which painstakingly uses EBNF syntax to clarify that the leading `-` sign is part of the number literal, which is just not the case. Why do they even bother with formal notation if the content is wrong? That is the lolphp.<|eoopr|><|sor|>That's a simple error in the documentation. Signs are not part of number literals. [Fixed.](https://github.com/php/doc-en/commit/687c48eff77e62c895b3f5fce6df0fc3936d3073)<|eor|><|soopr|>Dude, you just un-fixed [bug 45205](https://bugs.php.net/bug.php?id=45205)! This was not simply an error in the documentation; it was added in response to a bug report (after two months of deliberation) 11 years ago.<|eoopr|><|eoss|><|endoftext|>
6
lolphp
nexxai
axp3ye
<|sols|><|sot|>Bug opened 2006-08-22 and still open - PHP :: Bug #38546 :: bindParam incorrect processing of bool types<|eot|><|sol|>https://bugs.php.net/bug.php?id=38546<|eol|><|eols|><|endoftext|>
12
lolphp
dotancohen
ehwlm71
<|sols|><|sot|>Bug opened 2006-08-22 and still open - PHP :: Bug #38546 :: bindParam incorrect processing of bool types<|eot|><|sol|>https://bugs.php.net/bug.php?id=38546<|eol|><|sor|>I don't understand the sudden interest in old bugs on lolphp. Every project has decades-old bugs. One can sort by date and find some open PHP bugs from 2001 here: [https://bugs.php.net/search.php?order\_by=ts1&direction=ASC&cmd=display&status=Open&bug\_type=All&project=All&bug\_age=0&bug\_updated=0](https://bugs.php.net/search.php?search_for=&boolean=0&limit=30&order_by=ts1&direction=ASC&cmd=display&status=Open&bug_type=All&project=All&php_os=&phpver=&cve_id=&assign=&author_email=&bug_age=0&bug_updated=0&commented_by=) &#x200B; Shall I post the same for StarOffice (Libreoffice), Phoenix (Firefox), KDE, or the Linux kernel? Being old does not mean that a bug gets priority.<|eor|><|eols|><|endoftext|>
10
lolphp
ntzm_
akm5io
<|sols|><|sot|>The fuckery that is $http_response_header<|eot|><|sol|>https://twitter.com/asgrim/status/1089117795957256193<|eol|><|eols|><|endoftext|>
12