subreddit
stringclasses
7 values
author
stringlengths
3
20
id
stringlengths
5
7
content
stringlengths
67
30.4k
score
int64
0
140k
lolphp
drcforbin
h9b9gct
<|soss|><|sot|>Product Manager seeking recommendations on static code performance optimizers.<|eot|><|sost|>Hi Everyone. I am looking for a recommendation on a static PHP code analyzer for performance. I came from a Java background, so I am new to the PHP community. I am looking for a tool for a sniff test to determine if we need to consult outside resources to check out performance. Not as a replacement for a full performance audit. I am also looking for the pros and cons of such a tool and what results should be kept in perspective regarding the output. I thank you very much for your involvement.<|eost|><|sor|>One tool for displaying poorly performing PHP code is `cat`. It's pretty straightforward to use, just `cat filename.php` and it will print out the code that should be rewritten in another language.<|eor|><|eoss|><|endoftext|>
95
lolphp
colshrapnel
h9aqrw7
<|soss|><|sot|>Product Manager seeking recommendations on static code performance optimizers.<|eot|><|sost|>Hi Everyone. I am looking for a recommendation on a static PHP code analyzer for performance. I came from a Java background, so I am new to the PHP community. I am looking for a tool for a sniff test to determine if we need to consult outside resources to check out performance. Not as a replacement for a full performance audit. I am also looking for the pros and cons of such a tool and what results should be kept in perspective regarding the output. I thank you very much for your involvement.<|eost|><|sor|>Are you sure that's a correct subreddit for this request?<|eor|><|eoss|><|endoftext|>
36
lolphp
CarnivorousSociety
h9bhh2g
<|soss|><|sot|>Product Manager seeking recommendations on static code performance optimizers.<|eot|><|sost|>Hi Everyone. I am looking for a recommendation on a static PHP code analyzer for performance. I came from a Java background, so I am new to the PHP community. I am looking for a tool for a sniff test to determine if we need to consult outside resources to check out performance. Not as a replacement for a full performance audit. I am also looking for the pros and cons of such a tool and what results should be kept in perspective regarding the output. I thank you very much for your involvement.<|eost|><|sor|>lol /r/lostredditors<|eor|><|eoss|><|endoftext|>
19
lolphp
dwalker109
h9bjor3
<|soss|><|sot|>Product Manager seeking recommendations on static code performance optimizers.<|eot|><|sost|>Hi Everyone. I am looking for a recommendation on a static PHP code analyzer for performance. I came from a Java background, so I am new to the PHP community. I am looking for a tool for a sniff test to determine if we need to consult outside resources to check out performance. Not as a replacement for a full performance audit. I am also looking for the pros and cons of such a tool and what results should be kept in perspective regarding the output. I thank you very much for your involvement.<|eost|><|sor|>One tool for displaying poorly performing PHP code is `cat`. It's pretty straightforward to use, just `cat filename.php` and it will print out the code that should be rewritten in another language.<|eor|><|sor|>This is amazing<|eor|><|eoss|><|endoftext|>
15
lolphp
metamorphosis
h9clk14
<|soss|><|sot|>Product Manager seeking recommendations on static code performance optimizers.<|eot|><|sost|>Hi Everyone. I am looking for a recommendation on a static PHP code analyzer for performance. I came from a Java background, so I am new to the PHP community. I am looking for a tool for a sniff test to determine if we need to consult outside resources to check out performance. Not as a replacement for a full performance audit. I am also looking for the pros and cons of such a tool and what results should be kept in perspective regarding the output. I thank you very much for your involvement.<|eost|><|sor|>lol /r/lostredditors<|eor|><|sor|>No, just product manager doing product management things . Of course he is lost<|eor|><|eoss|><|endoftext|>
12
lolphp
intuxikated
h9azlf5
<|soss|><|sot|>Product Manager seeking recommendations on static code performance optimizers.<|eot|><|sost|>Hi Everyone. I am looking for a recommendation on a static PHP code analyzer for performance. I came from a Java background, so I am new to the PHP community. I am looking for a tool for a sniff test to determine if we need to consult outside resources to check out performance. Not as a replacement for a full performance audit. I am also looking for the pros and cons of such a tool and what results should be kept in perspective regarding the output. I thank you very much for your involvement.<|eost|><|sor|>This subreddit is created to mock the horrible language design of PHP I think you need a different subreddit for that question lol<|eor|><|eoss|><|endoftext|>
7
lolphp
antoniocs
h9e2yb4
<|soss|><|sot|>Product Manager seeking recommendations on static code performance optimizers.<|eot|><|sost|>Hi Everyone. I am looking for a recommendation on a static PHP code analyzer for performance. I came from a Java background, so I am new to the PHP community. I am looking for a tool for a sniff test to determine if we need to consult outside resources to check out performance. Not as a replacement for a full performance audit. I am also looking for the pros and cons of such a tool and what results should be kept in perspective regarding the output. I thank you very much for your involvement.<|eost|><|sor|>One tool for displaying poorly performing PHP code is `cat`. It's pretty straightforward to use, just `cat filename.php` and it will print out the code that should be rewritten in another language.<|eor|><|sor|>I loled<|eor|><|eoss|><|endoftext|>
6
lolphp
b1ackcat
h9ddhm7
<|soss|><|sot|>Product Manager seeking recommendations on static code performance optimizers.<|eot|><|sost|>Hi Everyone. I am looking for a recommendation on a static PHP code analyzer for performance. I came from a Java background, so I am new to the PHP community. I am looking for a tool for a sniff test to determine if we need to consult outside resources to check out performance. Not as a replacement for a full performance audit. I am also looking for the pros and cons of such a tool and what results should be kept in perspective regarding the output. I thank you very much for your involvement.<|eost|><|sor|>[deleted]<|eor|><|sor|>Seriously, OP. Not prod.<|eor|><|eoss|><|endoftext|>
5
lolphp
D1551D3N7
mlcj1o
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|eoss|><|endoftext|>
20
lolphp
carlos_vini
gtklzq4
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>https://www.php.net/manual/en/language.operators.precedence.php Using "or die()" is a bad practice, if you're seeing it in a 2021 tutorial stop following the tutorial. That's how things worked in 2005.<|eor|><|eoss|><|endoftext|>
35
lolphp
D1551D3N7
gtknjsx
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>https://www.php.net/manual/en/language.operators.precedence.php Using "or die()" is a bad practice, if you're seeing it in a 2021 tutorial stop following the tutorial. That's how things worked in 2005.<|eor|><|soopr|>Yeah this is a codebase I inherited, I didn't set it up this way.<|eoopr|><|eoss|><|endoftext|>
21
lolphp
Muzer0
gtky26w
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>What even made you start using `OR` and `||` without understanding what they each do separately? How about learning to crawl before walking or running? Like it's literally right there in the documentation page, the only text paragraph apart from table and code examples: [https://www.php.net/manual/en/language.operators.logical.php](https://www.php.net/manual/en/language.operators.logical.php) >The reason for the two different variations of "and" and "or" operators is that they operate at different precedences. (See [Operator Precedence](https://www.php.net/manual/en/language.operators.precedence.php).) Love or hate PHP, it doesn't matter. But if you stop guessing blindly when you code and start reading documentation for things, especially when their behaviour confuses you enough to write a social media post about them, you'll find that most of the things you find frustrating/confusing is actually just due to a knowledge gap in you that can be remedied.<|eor|><|sor|>Sure, but it's a language's job to make those knowledge gaps as small as possible. I mean if I made a language where every conditional statement to appear on a line number that's a multiple of 100 is actually inverted, you would call that a stupid language; even if I documented it perfectly clearly. PHP has tonnes of these "1 in 100" type weirdnesses that you just have to learn. Having two operators that are complete synonyms but with different precedences with no obvious reason why *is* stupid. Being condescending about it rather than admitting, yeah, we screwed up here, is the reason why /r/lolphp users think the real morons are those defending PHP rather than those who trip up on its confusing idiosyncrasies...<|eor|><|eoss|><|endoftext|>
16
lolphp
Muzer0
gtkxgfi
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>This confusion is quite understandable. Here is the explanation of your case in [layman's terms](https://phpdelusions.net/articles/or_die) Edit: language<|eor|><|sor|>Yes, but in every language that has `||` and `or` (well, C++ is the only one that comes to mind right now) they are synonyms. I don't know why on earth you would have two operators that seem like the same thing but give them different precedences...<|eor|><|eoss|><|endoftext|>
14
lolphp
yetzederixx
gtkstpe
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>This is fairly common. `|` and `||` behave differently in java. [https://stackoverflow.com/questions/4014535/differences-in-boolean-operators-vs-and-vs](https://stackoverflow.com/questions/4014535/differences-in-boolean-operators-vs-and-vs)<|eor|><|sor|>I would expect bitwise or and regular or to behave differently, however.<|eor|><|eoss|><|endoftext|>
14
lolphp
loptr
gtkpnv2
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>What even made you start using `OR` and `||` without understanding what they each do separately? How about learning to crawl before walking or running? Like it's literally right there in the documentation page, the only text paragraph apart from table and code examples: [https://www.php.net/manual/en/language.operators.logical.php](https://www.php.net/manual/en/language.operators.logical.php) >The reason for the two different variations of "and" and "or" operators is that they operate at different precedences. (See [Operator Precedence](https://www.php.net/manual/en/language.operators.precedence.php).) Love or hate PHP, it doesn't matter. But if you stop guessing blindly when you code and start reading documentation for things, especially when their behaviour confuses you enough to write a social media post about them, you'll find that most of the things you find frustrating/confusing is actually just due to a knowledge gap in you that can be remedied.<|eor|><|eoss|><|endoftext|>
13
lolphp
colshrapnel
gtkm7tb
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>This confusion is quite understandable. Here is the explanation of your case in [layman's terms](https://phpdelusions.net/articles/or_die) Edit: language<|eor|><|eoss|><|endoftext|>
12
lolphp
Muzer0
gtkxliv
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>This is fairly common. `|` and `||` behave differently in java. [https://stackoverflow.com/questions/4014535/differences-in-boolean-operators-vs-and-vs](https://stackoverflow.com/questions/4014535/differences-in-boolean-operators-vs-and-vs)<|eor|><|sor|>But `|` and `||` are different operators and make sense to have different precedences. `||` and `or` sound like synonyms - and they are in all but precedence. Just why, WTF?!<|eor|><|eoss|><|endoftext|>
12
lolphp
h0rst_
gtl6th3
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>This confusion is quite understandable. Here is the explanation of your case in [layman's terms](https://phpdelusions.net/articles/or_die) Edit: language<|eor|><|sor|>Yes, but in every language that has `||` and `or` (well, C++ is the only one that comes to mind right now) they are synonyms. I don't know why on earth you would have two operators that seem like the same thing but give them different precedences...<|eor|><|sor|>[Perl](https://perldoc.perl.org/perlop#Operator-Precedence-and-Associativity) [Ruby](https://ruby-doc.org/core-3.0.0/doc/syntax/precedence_rdoc.html) I remember tracking down a pretty nasty bug in Perl that was caused by the code `return A or B`. Apparently Perl parses this as `(return A) or B` and simply returns `A`. I've never used `and`, `or` and `not` in my code since.<|eor|><|eoss|><|endoftext|>
12
lolphp
colshrapnel
gtkmq3q
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>https://www.php.net/manual/en/language.operators.precedence.php Using "or die()" is a bad practice, if you're seeing it in a 2021 tutorial stop following the tutorial. That's how things worked in 2005.<|eor|><|sor|>Exactly! Also, working under the root is even worse<|eor|><|eoss|><|endoftext|>
11
lolphp
duskwuff
gtlaifv
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>This confusion is quite understandable. Here is the explanation of your case in [layman's terms](https://phpdelusions.net/articles/or_die) Edit: language<|eor|><|sor|>Yes, but in every language that has `||` and `or` (well, C++ is the only one that comes to mind right now) they are synonyms. I don't know why on earth you would have two operators that seem like the same thing but give them different precedences...<|eor|><|sor|>[Perl](https://perldoc.perl.org/perlop#Operator-Precedence-and-Associativity) [Ruby](https://ruby-doc.org/core-3.0.0/doc/syntax/precedence_rdoc.html) I remember tracking down a pretty nasty bug in Perl that was caused by the code `return A or B`. Apparently Perl parses this as `(return A) or B` and simply returns `A`. I've never used `and`, `or` and `not` in my code since.<|eor|><|sor|>And in Perl and Ruby, the fact that they have different precedences is intentional. That's the whole reason they have both -- it's to let you write things like $x = do_something() or die "failed to do something"; as a shorthand for: if (!($x = do_something)) { die "failed to do something"; }<|eor|><|eoss|><|endoftext|>
9
lolphp
Muzer0
gtky7gm
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>https://www.php.net/manual/en/language.operators.precedence.php Using "or die()" is a bad practice, if you're seeing it in a 2021 tutorial stop following the tutorial. That's how things worked in 2005.<|eor|><|soopr|>Yeah this is a codebase I inherited, I didn't set it up this way.<|eoopr|><|sor|>Dunno why you were downvoted for this. I suspect half the people trawling programming subreddits have never written more than pet projects where every line of code can be perfectly refined...<|eor|><|eoss|><|endoftext|>
7
lolphp
ealf
gtq14er
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>Don't get distracted by the `($a = 3) or 4` vs `$a = (3 || 4)` difference inherited from Perl -- this shouldn't matter in this context. The real problem is that `3 || 4` and `3 or 4` are both `true`, not `3`.<|eor|><|eoss|><|endoftext|>
6
lolphp
sproingie
gtmnqg3
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>https://www.php.net/manual/en/language.operators.precedence.php Using "or die()" is a bad practice, if you're seeing it in a 2021 tutorial stop following the tutorial. That's how things worked in 2005.<|eor|><|sor|>Now that `throw` is an expression, `or throw` is a decent replacement.<|eor|><|eoss|><|endoftext|>
5
lolphp
ZiggyTheHamster
gtlxebn
<|soss|><|sot|>Or and || act differently in some contexts<|eot|><|sost|> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myFile = fopen('/tmp/aaaaaaaaaa', "a") or die('unable to open'); fwrite($myFile,'ok lol'); fclose($myFile); $myFile2 = fopen('/tmp/bbbbbbbbbb', "a") || die('unable to open'); fwrite($myFile2,'ok lol'); fclose($myFile2); ?> Save that to a file and then do the following: root@server:/var/www/html# php /tmp/test.php PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 Warning: fwrite() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 10 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 Warning: fclose() expects parameter 1 to be resource, boolean given in /tmp/test.php on line 11 root@server:/var/www/html# cat /tmp/aaaaaaaaaa ok lol root@server:/var/www/html# cat /tmp/bbbbbbbbbb root@server:/var/www/html# This thing took ages to debug and makes no fucking sense I swear to god aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<|eost|><|sor|>What even made you start using `OR` and `||` without understanding what they each do separately? How about learning to crawl before walking or running? Like it's literally right there in the documentation page, the only text paragraph apart from table and code examples: [https://www.php.net/manual/en/language.operators.logical.php](https://www.php.net/manual/en/language.operators.logical.php) >The reason for the two different variations of "and" and "or" operators is that they operate at different precedences. (See [Operator Precedence](https://www.php.net/manual/en/language.operators.precedence.php).) Love or hate PHP, it doesn't matter. But if you stop guessing blindly when you code and start reading documentation for things, especially when their behaviour confuses you enough to write a social media post about them, you'll find that most of the things you find frustrating/confusing is actually just due to a knowledge gap in you that can be remedied.<|eor|><|sor|>Sure, but it's a language's job to make those knowledge gaps as small as possible. I mean if I made a language where every conditional statement to appear on a line number that's a multiple of 100 is actually inverted, you would call that a stupid language; even if I documented it perfectly clearly. PHP has tonnes of these "1 in 100" type weirdnesses that you just have to learn. Having two operators that are complete synonyms but with different precedences with no obvious reason why *is* stupid. Being condescending about it rather than admitting, yeah, we screwed up here, is the reason why /r/lolphp users think the real morons are those defending PHP rather than those who trip up on its confusing idiosyncrasies...<|eor|><|sor|>> Having two operators that are complete synonyms but with different precedences with no obvious reason why is stupid. They're not synonyms. Plenty of other languages do this. Off the top of my head, both Ruby and Perl have this (`or` and `||` are different as are `and` and `&&`), and I suspect that both Ruby and PHP picked that up from Perl. I will admit that the docs are ridiculous here and don't explain this in adequate detail. Edit: In Ruby, I use rubocop to identify these landmines. Is there not an equivalent linter for PHP?<|eor|><|eoss|><|endoftext|>
5
lolphp
girst
d1gic6
<|sols|><|sot|>Rasmus Lendorf on 25 years of PHP (and its mistakes)<|eot|><|sol|>https://www.youtube.com/watch?v=wCZ5TJCBWMg<|eol|><|eols|><|endoftext|>
19
lolphp
jsanc623
ezmaj7x
<|sols|><|sot|>Rasmus Lendorf on 25 years of PHP (and its mistakes)<|eot|><|sol|>https://www.youtube.com/watch?v=wCZ5TJCBWMg<|eol|><|soopr|>Some explanations make sense, others don't to me (like how he on the one hand says that he expected PHP to die within half a year, yet kept pushing new features and performance hacks). It's been years since I did any PHP, but it's interesting how the language evolved since too.<|eoopr|><|sor|>>Some explanations make sense, others don't to me (like how he on the one hand says that he expected PHP to die within half a year, yet kept pushing new features and performance hacks). It's possible to keep pushing features and expect usage to drop to the point that it can be considered "dead". The two are not mutual.<|eor|><|eols|><|endoftext|>
9
lolphp
girst
ezlc97b
<|sols|><|sot|>Rasmus Lendorf on 25 years of PHP (and its mistakes)<|eot|><|sol|>https://www.youtube.com/watch?v=wCZ5TJCBWMg<|eol|><|soopr|>Some explanations make sense, others don't to me (like how he on the one hand says that he expected PHP to die within half a year, yet kept pushing new features and performance hacks). It's been years since I did any PHP, but it's interesting how the language evolved since too.<|eoopr|><|eols|><|endoftext|>
7
lolphp
PGLubricants
ckexmw
<|sols|><|sot|>You probably heard of variables, but what about variable variables?<|eot|><|sol|>https://www.php.net/manual/en/language.variables.variable.php<|eol|><|eols|><|endoftext|>
20
lolphp
AlbertRammstein
evmqduk
<|sols|><|sot|>You probably heard of variables, but what about variable variables?<|eot|><|sol|>https://www.php.net/manual/en/language.variables.variable.php<|eol|><|sor|>The first line of documentation is a big ooooof/[citation needed] from me "Sometimes it is convenient to be able to have variable variable names"<|eor|><|eols|><|endoftext|>
28
lolphp
scotchanddonuts
evn2l6b
<|sols|><|sot|>You probably heard of variables, but what about variable variables?<|eot|><|sol|>https://www.php.net/manual/en/language.variables.variable.php<|eol|><|sor|>In most other languages this is just called "reflection".<|eor|><|eols|><|endoftext|>
19
lolphp
Altreus
evpvpni
<|sols|><|sot|>You probably heard of variables, but what about variable variables?<|eot|><|sol|>https://www.php.net/manual/en/language.variables.variable.php<|eol|><|sor|>Every other language: We have a feature so you can't accidentally use variables that don't exist because we learned it was a big problem with no benefit PHP: Here's how to introduce bugs on purpose<|eor|><|eols|><|endoftext|>
16
lolphp
Miserable_Fuck
evn0qkh
<|sols|><|sot|>You probably heard of variables, but what about variable variables?<|eot|><|sol|>https://www.php.net/manual/en/language.variables.variable.php<|eol|><|sor|>The first line of documentation is a big ooooof/[citation needed] from me "Sometimes it is convenient to be able to have variable variable names"<|eor|><|sor|>came here to say exactly this. i reject the fundamental premise of that entire page.<|eor|><|eols|><|endoftext|>
12
lolphp
mktiti
evpadbu
<|sols|><|sot|>You probably heard of variables, but what about variable variables?<|eot|><|sol|>https://www.php.net/manual/en/language.variables.variable.php<|eol|><|sor|>In most other languages this is just called "reflection".<|eor|><|sor|>No, it is like pointers.<|eor|><|sor|>But it doesn't 'point' to a memory location, it is a name lookup, which is more like reflections.<|eor|><|eols|><|endoftext|>
12
lolphp
PGLubricants
evpbrof
<|sols|><|sot|>You probably heard of variables, but what about variable variables?<|eot|><|sol|>https://www.php.net/manual/en/language.variables.variable.php<|eol|><|soopr|>To add to the madness, the top user-contributed note shows this nifty example: <?php //You can even add more Dollar Signs $Bar = "a"; $Foo = "Bar"; $World = "Foo"; $Hello = "World"; $a = "Hello"; $a; //Returns Hello $$a; //Returns World $$$a; //Returns Foo $$$$a; //Returns Bar $$$$$a; //Returns a $$$$$$a; //Returns Hello $$$$$$$a; //Returns World //... and so on ...// ?><|eoopr|><|eols|><|endoftext|>
10
lolphp
oipoi
evonerh
<|sols|><|sot|>You probably heard of variables, but what about variable variables?<|eot|><|sol|>https://www.php.net/manual/en/language.variables.variable.php<|eol|><|sor|>The first line of documentation is a big ooooof/[citation needed] from me "Sometimes it is convenient to be able to have variable variable names"<|eor|><|sor|>Damn, thought that you did a mock quote to summarize the jist of the page, but it really starts off like that.<|eor|><|eols|><|endoftext|>
10
lolphp
stfcfanhazz
evmr5dl
<|sols|><|sot|>You probably heard of variables, but what about variable variables?<|eot|><|sol|>https://www.php.net/manual/en/language.variables.variable.php<|eol|><|sor|>I actually have used this a fair bit but normally for object properties or array indexes in certain specific circumstances. Magic begets magic- php is so dynamic it almost hurts<|eor|><|eols|><|endoftext|>
5
lolphp
babyra
4lzhye
<|sols|><|sot|>Php programmer makes awesome discovery and the fellow php programmers cheer on...<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/4lu3gf/deferred_execution_in_php_using_finally/<|eol|><|eols|><|endoftext|>
18
lolphp
maweki
d3riacu
<|sols|><|sot|>Php programmer makes awesome discovery and the fellow php programmers cheer on...<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/4lu3gf/deferred_execution_in_php_using_finally/<|eol|><|sor|>First they rediscover all the features from other languages, now they rediscover how to use those features. Good for them, I say.<|eor|><|eols|><|endoftext|>
30
lolphp
Takeoded
d3rvei2
<|sols|><|sot|>Php programmer makes awesome discovery and the fellow php programmers cheer on...<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/4lu3gf/deferred_execution_in_php_using_finally/<|eol|><|sor|>[deleted]<|eor|><|sor|>http://www.urbandictionary.com/define.php?term=Genious<|eor|><|eols|><|endoftext|>
18
lolphp
armornick
d3rh93n
<|sols|><|sot|>Php programmer makes awesome discovery and the fellow php programmers cheer on...<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/4lu3gf/deferred_execution_in_php_using_finally/<|eol|><|sor|>> fact that finally can replace catch entirely is a testament to the fact that it doesn't have to have anything to do with the catch block Err, what?<|eor|><|eols|><|endoftext|>
13
lolphp
tdammers
d3rk5oe
<|sols|><|sot|>Php programmer makes awesome discovery and the fellow php programmers cheer on...<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/4lu3gf/deferred_execution_in_php_using_finally/<|eol|><|sor|>The funniest / saddest part is that, like everything in PHP land, this pseudo-RAII works fine, until it doesn't.<|eor|><|eols|><|endoftext|>
13
lolphp
autourbanbot
d3rvfde
<|sols|><|sot|>Php programmer makes awesome discovery and the fellow php programmers cheer on...<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/4lu3gf/deferred_execution_in_php_using_finally/<|eol|><|sor|>[deleted]<|eor|><|sor|>http://www.urbandictionary.com/define.php?term=Genious<|eor|><|sor|>*Here's the Urban Dictionary definition of* [***Genious***](http://www.urbandictionary.com/define.php?term=genious) : --- >It is often the case that idiots describe themselves as 'genious' but are ironically ignorant to the fact that the word is spelt 'genius' - much to the amusement of us intelligent people. --- _"Like, woah, yeah man, I'm like, such a genious, dude!"_ _"Well, you're retarded..."_ --- [^(about)](http://www.reddit.com/r/autourbanbot/wiki/index) ^| [^(flag for glitch)](http://www.reddit.com/message/compose?to=/r/autourbanbot&subject=bot%20glitch&message=%0Acontext:https://www.reddit.com/r/lolphp/comments/4lzhye/php_programmer_makes_awesome_discovery_and_the/d3rvei2) ^| ^(**Summon**: urbanbot, what is something?)<|eor|><|eols|><|endoftext|>
13
lolphp
the_pw_is_in_this_ID
d3s1io0
<|sols|><|sot|>Php programmer makes awesome discovery and the fellow php programmers cheer on...<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/4lu3gf/deferred_execution_in_php_using_finally/<|eol|><|sor|>> fact that finally can replace catch entirely is a testament to the fact that it doesn't have to have anything to do with the catch block Err, what?<|eor|><|sor|>He's right though. The functionality of a Finally block are agnostic to the contents (or even presence) of a Catch block. (Unless you have weird state manipulation or something in your catch block. If so, then god help you.)<|eor|><|eols|><|endoftext|>
6
lolphp
the_pw_is_in_this_ID
d3u6cyr
<|sols|><|sot|>Php programmer makes awesome discovery and the fellow php programmers cheer on...<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/4lu3gf/deferred_execution_in_php_using_finally/<|eol|><|sor|>> fact that finally can replace catch entirely is a testament to the fact that it doesn't have to have anything to do with the catch block Err, what?<|eor|><|sor|>He's right though. The functionality of a Finally block are agnostic to the contents (or even presence) of a Catch block. (Unless you have weird state manipulation or something in your catch block. If so, then god help you.)<|eor|><|sor|>But catch and finally are normally inherently connected. Omitting the catch block is the same as putting an empty catch block, sure, but you're still catching errors and doing something when you're done "handling them". To say that they don't have anything to do with them is a bit of a stretch.<|eor|><|sor|>I don't see what you're meaning... 'Finally' simply denotes code which will always be executed. This will happen after errors are handled, or after the try is completed normally. You don't need to catch exceptional execution for the finally to execute - that's quite the point of the whole thing. The finally is indifferent to the catch.<|eor|><|eols|><|endoftext|>
6
lolphp
iheartrms
360twc
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|eols|><|endoftext|>
17
lolphp
JiminP
cr9u5m4
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>This isn't a PHP hash comparison flaw (nor is it a lolphp). This is people not using the correct operator, or (better) using a timing-safe hash comparison function. == is "loose comparison". "0e" is valid notation for a exponent in a string. JS will suffer from similar issues with ==. Sorry, yet again, another not "lolphp" but "loldeveloper". FTR: PHP5.6 has a timing safe hash comparison function built in called hash_equals, along with several other hashing methods designed to eliminate developer error.<|eor|><|sor|>No, JS will not suffer from the issue. `"0e123" != "0e456"` in JavaScript (because comparisons between strings are done by... doing string comparisons; between same types, `==` is *always* equivalent to `===` (compare [11.9.3](http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3) and [11.9.6](http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.6))), but `"0e123" == "0e456"` in PHP, because strings [are converted to numbers](http://php.net/manual/en/language.operators.comparison.php) during comparison.<|eor|><|eols|><|endoftext|>
30
lolphp
tdammers
cr9u02i
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>How is this a "new vulnerability"? PHP's "loose comparison operators" (`==` and `!=`) have been broken since 1.0, and will be until the sun dies a heat death. You don't use `==` in security-relevant code, period. Or actually, don't use `==` ever, it's just not worth it.<|eor|><|eols|><|endoftext|>
22
lolphp
OneWingedShark
crau1sy
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>How is this a "new vulnerability"? PHP's "loose comparison operators" (`==` and `!=`) have been broken since 1.0, and will be until the sun dies a heat death. You don't use `==` in security-relevant code, period. Or actually, don't use `==` ever, it's just not worth it.<|eor|><|sor|>> You don't use ~~==~~ ***PHP*** in security-relevant code, period. FTFY. <|eor|><|eols|><|endoftext|>
16
lolphp
vita10gy
cra1c9a
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>This isn't a PHP hash comparison flaw (nor is it a lolphp). This is people not using the correct operator, or (better) using a timing-safe hash comparison function. == is "loose comparison". "0e" is valid notation for a exponent in a string. JS will suffer from similar issues with ==. Sorry, yet again, another not "lolphp" but "loldeveloper". FTR: PHP5.6 has a timing safe hash comparison function built in called hash_equals, along with several other hashing methods designed to eliminate developer error.<|eor|><|sor|>To any programmer unfamiliar with truthy/falsey values (because it's not a thing in many languages), this would definitely be a lolphp.<|eor|><|sor|>Programming is literally manipulating true/false statements. If a programmer is unfamiliar with this, thy're not a rpogramer <|eor|><|sor|>The vast majority of languages treat == as either value or reference equality, *not* as a type coercion operator. You basically have php and Javascript which do, and then more sensible languages which don't. It would be perfectly reasonable for somebody who only has experience writing languages which aren't php or Javascript to assume that the equality and inequality operators test for some form of equality. <|eor|><|sor|>True. Sane languages would never convert *both* sides of the comparison operator to a different type, if they are the same type to begin with: if you compare two strings, it should compare as strings; if you compare two numbers, it should compare as numbers. Only if both sides are not the same type should it be allowed to coerce them into the same type first. Thus: 0=="0e10" may be considered as true, but "0e11"=="0e10" should *always* be false. And that makes it lolphp. <|eor|><|sor|>Just think about the somewhat understandable way this probably came about: `$GET` contains strings, your database API returns everything as strings, you want to compare number encoded on both sides. Sane solution: write code such that both are converted to numbers before doing any logic on them, then use numeric comparison. PHP solution: invent an operator that guesses whether you means string comparison or numeric comparison given insufficient information. This is something that permeates PHP culture so deeply, it's sickening. Why use a DOM representation when search-and-replace on the HTML source also kind of sort of almost works? Why provide a DB API that has parametrized queries in order to prevent SQLi, when we can have `magic_quotes`? PHP is full of this shit, and that's not OK, but then, I doubt many PHP people even see the pattern here.<|eor|><|sor|>For what it's worth, I'm a full time PHP dev, and semi frequently defend the "lolphps" on here (often they're stupid things the dev is doing.) That said, PHP is a flaming turd burger, and I'm not really sure why anyone thinks otherwise. Almost every one of PHPs glaring flaws, yours included, it rooted in PHP being "easier" to program in. The problem with being "easier" to program in, is that it virtually ALWAYS comes at the cost of something else being a confusing royal pain in the ass. From the minor, such as not needing to declare variables and types being great...until you have to maintain anything and have no idea where $temp is coming from and when the hell $title became a 5 instead of a string. To the major, such as issues like this. Seriously? I have to use === in almost all string comparisons, because god forbid "1000" == "1e3" fails? That's insanity. Even a loosly typed language like PHP should behave sanely, and comparing strings as strings and leaving it up to the programmer to do (int)"1000" == (int)"1e3" the 4 times in his life where that matters is the sane thing. But type casting is hard, so I'll just guess at what you meant. Easy and nonsensical is always better than hard. Warnings and errors and other "protect you from you" things are hard. For that matter, is string to int even the right direction to go there? shouldn't 1000 == "1e3" get implicitly converted to "1000" == "1e3" and be false? Seems like only trouble to go the other way with it in the first place. Int to string is safe. No matter how you slice it, white washing over shit like this with "Derp RTFM and use ===" is silly, because the very fact that PHP needs a === is a problem. (Or, at the very least, I don't know how anyone can say "You just never use ==" and then move on, like that isn't a problem with a language that literally the most common comparison a programmer does is fundamentally useless.)<|eor|><|eols|><|endoftext|>
16
lolphp
tdammers
cr9tzth
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>This isn't a PHP hash comparison flaw (nor is it a lolphp). This is people not using the correct operator, or (better) using a timing-safe hash comparison function. == is "loose comparison". "0e" is valid notation for a exponent in a string. JS will suffer from similar issues with ==. Sorry, yet again, another not "lolphp" but "loldeveloper". FTR: PHP5.6 has a timing safe hash comparison function built in called hash_equals, along with several other hashing methods designed to eliminate developer error.<|eor|><|sor|>To any programmer unfamiliar with truthy/falsey values (because it's not a thing in many languages), this would definitely be a lolphp.<|eor|><|sor|>Programming is literally manipulating true/false statements. If a programmer is unfamiliar with this, thy're not a rpogramer <|eor|><|sor|>The vast majority of languages treat == as either value or reference equality, *not* as a type coercion operator. You basically have php and Javascript which do, and then more sensible languages which don't. It would be perfectly reasonable for somebody who only has experience writing languages which aren't php or Javascript to assume that the equality and inequality operators test for some form of equality. <|eor|><|sor|>True. Sane languages would never convert *both* sides of the comparison operator to a different type, if they are the same type to begin with: if you compare two strings, it should compare as strings; if you compare two numbers, it should compare as numbers. Only if both sides are not the same type should it be allowed to coerce them into the same type first. Thus: 0=="0e10" may be considered as true, but "0e11"=="0e10" should *always* be false. And that makes it lolphp. <|eor|><|sor|>Just think about the somewhat understandable way this probably came about: `$GET` contains strings, your database API returns everything as strings, you want to compare number encoded on both sides. Sane solution: write code such that both are converted to numbers before doing any logic on them, then use numeric comparison. PHP solution: invent an operator that guesses whether you means string comparison or numeric comparison given insufficient information. This is something that permeates PHP culture so deeply, it's sickening. Why use a DOM representation when search-and-replace on the HTML source also kind of sort of almost works? Why provide a DB API that has parametrized queries in order to prevent SQLi, when we can have `magic_quotes`? PHP is full of this shit, and that's not OK, but then, I doubt many PHP people even see the pattern here.<|eor|><|eols|><|endoftext|>
14
lolphp
bart2019
cr9t6v1
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>This isn't a PHP hash comparison flaw (nor is it a lolphp). This is people not using the correct operator, or (better) using a timing-safe hash comparison function. == is "loose comparison". "0e" is valid notation for a exponent in a string. JS will suffer from similar issues with ==. Sorry, yet again, another not "lolphp" but "loldeveloper". FTR: PHP5.6 has a timing safe hash comparison function built in called hash_equals, along with several other hashing methods designed to eliminate developer error.<|eor|><|sor|>To any programmer unfamiliar with truthy/falsey values (because it's not a thing in many languages), this would definitely be a lolphp.<|eor|><|sor|>Programming is literally manipulating true/false statements. If a programmer is unfamiliar with this, thy're not a rpogramer <|eor|><|sor|>The vast majority of languages treat == as either value or reference equality, *not* as a type coercion operator. You basically have php and Javascript which do, and then more sensible languages which don't. It would be perfectly reasonable for somebody who only has experience writing languages which aren't php or Javascript to assume that the equality and inequality operators test for some form of equality. <|eor|><|sor|>True. Sane languages would never convert *both* sides of the comparison operator to a different type, if they are the same type to begin with: if you compare two strings, it should compare as strings; if you compare two numbers, it should compare as numbers. Only if both sides are not the same type should it be allowed to coerce them into the same type first. Thus: 0=="0e10" may be considered as true, but "0e11"=="0e10" should *always* be false. And that makes it lolphp. <|eor|><|eols|><|endoftext|>
10
lolphp
phoshi
cr9vkp0
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>This isn't a PHP hash comparison flaw (nor is it a lolphp). This is people not using the correct operator, or (better) using a timing-safe hash comparison function. == is "loose comparison". "0e" is valid notation for a exponent in a string. JS will suffer from similar issues with ==. Sorry, yet again, another not "lolphp" but "loldeveloper". FTR: PHP5.6 has a timing safe hash comparison function built in called hash_equals, along with several other hashing methods designed to eliminate developer error.<|eor|><|sor|>To any programmer unfamiliar with truthy/falsey values (because it's not a thing in many languages), this would definitely be a lolphp.<|eor|><|sor|>Programming is literally manipulating true/false statements. If a programmer is unfamiliar with this, thy're not a rpogramer <|eor|><|sor|>The vast majority of languages treat == as either value or reference equality, *not* as a type coercion operator. You basically have php and Javascript which do, and then more sensible languages which don't. It would be perfectly reasonable for somebody who only has experience writing languages which aren't php or Javascript to assume that the equality and inequality operators test for some form of equality. <|eor|><|sor|>RTFM<|eor|><|sor|>Something being in the manual does not make it reasonable, it just means they've written down their unreasonable behaviour. <|eor|><|sor|>It is very reasonable to have this behaviour in any untyped language. Go back to Haskell if you can't manage simple abstractions like this and stop making excuses to hate PHP when it's not an issue.<|eor|><|sor|>How is this not an issue? Nobody else does this. Python does not, ruby does not. Perl is not as aggressive about it and perl 6 is moving away from even that. But okay, let's look at this pragmatically. You say this isn't a problem because it's documented and people shouldn't use the operator in cases where it could be problematic. So you can't use it to compare user supplied strings, okay. You can't use it to compare strings generated from non-user input either, because it might be in one of the many problematic formats. I guess you can still use it on compile time constants, but why on earth would you need a type coercive compare on things you know at compile time? So you just never use the operator, but it's still okay, because it's documented as something you should clearly never use. We add another = sign and move on, no problem. Except there are no non type coercive ordering operators. You can't do < or > without coercing, and as we've already decided, you can't use coercive operators on anything but compile time constants. So I guess you have to use library functions instead. How is that state of affairs not absurd? The basic set of logical operators are not safe to use with anything which isn't known at compile time. No other language suffers this, it is a tremendous pitfall which anyone learning the language will fall into, because why the fuck would you memorise the truth table for your comparison operator when every other mainstream language (save Javascript) doesn't fuck it up. <|eor|><|eols|><|endoftext|>
10
lolphp
tdammers
cragso7
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>How is this a "new vulnerability"? PHP's "loose comparison operators" (`==` and `!=`) have been broken since 1.0, and will be until the sun dies a heat death. You don't use `==` in security-relevant code, period. Or actually, don't use `==` ever, it's just not worth it.<|eor|><|sor|>[deleted]<|eor|><|sor|>Every time I thought there was, it turned out not to be. I'm sure the time and place for `==` exists somewhere out there, but looking for it gets old quick.<|eor|><|eols|><|endoftext|>
9
lolphp
phoshi
cr9rmw5
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>This isn't a PHP hash comparison flaw (nor is it a lolphp). This is people not using the correct operator, or (better) using a timing-safe hash comparison function. == is "loose comparison". "0e" is valid notation for a exponent in a string. JS will suffer from similar issues with ==. Sorry, yet again, another not "lolphp" but "loldeveloper". FTR: PHP5.6 has a timing safe hash comparison function built in called hash_equals, along with several other hashing methods designed to eliminate developer error.<|eor|><|sor|>To any programmer unfamiliar with truthy/falsey values (because it's not a thing in many languages), this would definitely be a lolphp.<|eor|><|sor|>Programming is literally manipulating true/false statements. If a programmer is unfamiliar with this, thy're not a rpogramer <|eor|><|sor|>The vast majority of languages treat == as either value or reference equality, *not* as a type coercion operator. You basically have php and Javascript which do, and then more sensible languages which don't. It would be perfectly reasonable for somebody who only has experience writing languages which aren't php or Javascript to assume that the equality and inequality operators test for some form of equality. <|eor|><|eols|><|endoftext|>
9
lolphp
phoshi
cr9tqhh
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>This isn't a PHP hash comparison flaw (nor is it a lolphp). This is people not using the correct operator, or (better) using a timing-safe hash comparison function. == is "loose comparison". "0e" is valid notation for a exponent in a string. JS will suffer from similar issues with ==. Sorry, yet again, another not "lolphp" but "loldeveloper". FTR: PHP5.6 has a timing safe hash comparison function built in called hash_equals, along with several other hashing methods designed to eliminate developer error.<|eor|><|sor|>To any programmer unfamiliar with truthy/falsey values (because it's not a thing in many languages), this would definitely be a lolphp.<|eor|><|sor|>Programming is literally manipulating true/false statements. If a programmer is unfamiliar with this, thy're not a rpogramer <|eor|><|sor|>The vast majority of languages treat == as either value or reference equality, *not* as a type coercion operator. You basically have php and Javascript which do, and then more sensible languages which don't. It would be perfectly reasonable for somebody who only has experience writing languages which aren't php or Javascript to assume that the equality and inequality operators test for some form of equality. <|eor|><|sor|>It's still user error that they're using an operator incorrectly.<|eor|><|sor|>Documenting insanity does not make it go away, therefore it is unreasonable to expect people to memorise equality tables for a common operator. Every other language, save Javascript, gets this right. This isn't a case of some esoteric functionality being hard, it is a case of literally the most common functionality being astonishing. <|eor|><|eols|><|endoftext|>
9
lolphp
gu3st12
cr9p2wi
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>This isn't a PHP hash comparison flaw (nor is it a lolphp). This is people not using the correct operator, or (better) using a timing-safe hash comparison function. == is "loose comparison". "0e" is valid notation for a exponent in a string. JS will suffer from similar issues with ==. Sorry, yet again, another not "lolphp" but "loldeveloper". FTR: PHP5.6 has a timing safe hash comparison function built in called hash_equals, along with several other hashing methods designed to eliminate developer error.<|eor|><|eols|><|endoftext|>
8
lolphp
WrasslorMonkey
cr9rdrs
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>This isn't a PHP hash comparison flaw (nor is it a lolphp). This is people not using the correct operator, or (better) using a timing-safe hash comparison function. == is "loose comparison". "0e" is valid notation for a exponent in a string. JS will suffer from similar issues with ==. Sorry, yet again, another not "lolphp" but "loldeveloper". FTR: PHP5.6 has a timing safe hash comparison function built in called hash_equals, along with several other hashing methods designed to eliminate developer error.<|eor|><|sor|>To any programmer unfamiliar with truthy/falsey values (because it's not a thing in many languages), this would definitely be a lolphp.<|eor|><|eols|><|endoftext|>
5
lolphp
merreborn
craev7y
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>And shit like this is why I ALWAYS type check.<|eor|><|sor|>Using `===` still leaves you vulnerable to timing attacks. When comparing hashes, `hash_equals()` is the only safe comparator. <|eor|><|eols|><|endoftext|>
5
lolphp
tdammers
cra5iyp
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>How is this a "new vulnerability"? PHP's "loose comparison operators" (`==` and `!=`) have been broken since 1.0, and will be until the sun dies a heat death. You don't use `==` in security-relevant code, period. Or actually, don't use `==` ever, it's just not worth it.<|eor|><|sor|>the md5() documentation examples even uses ===<|eor|><|sor|>Except that md5 is a convenience hash, not a secure hash. But yes.<|eor|><|eols|><|endoftext|>
5
lolphp
Kwpolska
csdnpa4
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>How is this a "new vulnerability"? PHP's "loose comparison operators" (`==` and `!=`) have been broken since 1.0, and will be until the sun dies a heat death. You don't use `==` in security-relevant code, period. Or actually, don't use `==` ever, it's just not worth it.<|eor|><|sor|>> You don't use ~~==~~ ***PHP*** in security-relevant code, period. FTFY. <|eor|><|sor|>> You dont use PHP, period. FTFY.<|eor|><|eols|><|endoftext|>
5
lolphp
merreborn
craitqw
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>And shit like this is why I ALWAYS type check.<|eor|><|sor|>Using `===` still leaves you vulnerable to timing attacks. When comparing hashes, `hash_equals()` is the only safe comparator. <|eor|><|sor|>> Using === still leaves you vulnerable to timing attacks. How so? <|eor|><|sor|>http://en.wikipedia.org/wiki/Timing_attack === returns as soon as it hits the first non-matching char (as does ==). A timing attack exploits this, by watching how long comparison takes, and thus deducing how many characters of a test string match the secret. To prevent this, comparisons should be constant-time when comparing a user-supplied token against a secret hash. `===` is not constant time. hash_equals() is.<|eor|><|eols|><|endoftext|>
5
lolphp
phoshi
cr9tqtt
<|sols|><|sot|>PHP hash comparison flaw is a risk for million users<|eot|><|sol|>http://securityaffairs.co/wordpress/36732/hacking/php-hash-comparison-flaw.html<|eol|><|sor|>This isn't a PHP hash comparison flaw (nor is it a lolphp). This is people not using the correct operator, or (better) using a timing-safe hash comparison function. == is "loose comparison". "0e" is valid notation for a exponent in a string. JS will suffer from similar issues with ==. Sorry, yet again, another not "lolphp" but "loldeveloper". FTR: PHP5.6 has a timing safe hash comparison function built in called hash_equals, along with several other hashing methods designed to eliminate developer error.<|eor|><|sor|>To any programmer unfamiliar with truthy/falsey values (because it's not a thing in many languages), this would definitely be a lolphp.<|eor|><|sor|>Programming is literally manipulating true/false statements. If a programmer is unfamiliar with this, thy're not a rpogramer <|eor|><|sor|>The vast majority of languages treat == as either value or reference equality, *not* as a type coercion operator. You basically have php and Javascript which do, and then more sensible languages which don't. It would be perfectly reasonable for somebody who only has experience writing languages which aren't php or Javascript to assume that the equality and inequality operators test for some form of equality. <|eor|><|sor|>RTFM<|eor|><|sor|>Something being in the manual does not make it reasonable, it just means they've written down their unreasonable behaviour. <|eor|><|eols|><|endoftext|>
5
lolphp
fnzp
2g681k
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|eols|><|endoftext|>
18
lolphp
DoubleNabla
ckgf6zr
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|sor|>Getting it "right" is hard to define if the code is wrong.<|eor|><|sor|>Yes, but of course, [the documentation](http://php.net/manual/en/function.strcmp.php) is even more wronger: > Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. What it doesn't mention is that it [returns **NULL** when you pass an array...](http://3v4l.org/N4hYT#v530) EDIT: [didn't we have that already?](http://danuxx.blogspot.co.uk/2013/03/unauthorized-access-bypassing-php-strcmp.html)<|eor|><|sor|>The documentation says it's for string comparison, why would you pass an array to it?<|eor|><|sor|>"Everyone knows you shouldn't set your house on fire, why would you do it? Get rid of that useless smoke detector." Yes, of course you _shouldn't_ do it, I'd hope we have this already established. The problem is that, should you accidentally do it, it reacts in a completely unexpected and unintuitive way that also happens to be highly dangerous, _and continues_, and the documentation doesn't mention that. There is no reason why it shouldn't throw a fatal error (as you said, the documentation says it's for strings), or at the very least not _return a value that php-equals the one returned if the two parameters are equal strings_.<|eor|><|eols|><|endoftext|>
18
lolphp
PhantomRacer
ckg6vkp
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|sor|>Getting it "right" is hard to define if the code is wrong.<|eor|><|eols|><|endoftext|>
11
lolphp
fnzp
ckgkmfa
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|sor|>Getting it "right" is hard to define if the code is wrong.<|eor|><|soopr|>Not true. Getting it right when the code is wrong is the easiest: die("YOUR CODE IS WRONG FIX IT OR THIS PROGRAM CAN'T RUN"); This is one of the major problems in PHP. Instead of dying and forcing the programmer to fix the mistakes, it just keeps on trucking. With so many possible ways to make mistakes, this is sure to lead to problems.<|eoopr|><|eols|><|endoftext|>
8
lolphp
fnzp
ckhoe95
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|sor|>Wouldn't it be a better comparison if the code didn't have dozens of notices and warning? Or does it only do something wrong if your code is wrong and full of errors?<|eor|><|soopr|>Yes you're right. So add "error_reporting(E_ERROR);" to the top to fix that little problem! http://3v4l.org/ZEjJ9 Ahhh all better!<|eoopr|><|sor|>uh, that doesn't fix the problem... The code is still wrong. You just silenced the warnings. Show me strcmp() doing something wrong when your code isn't doing incredibly silly things and shouting warnings everywhere, then we'll talk.<|eor|><|soopr|>The code isn't wrong. The input data is wrong. Silencing warnings is fine in production code. So the code isn't "shouting warnings everywhere", because they are "silenced" like you say. The code isn't doing "incredibly silly things". This is valid PHP5.2.x code. This code works up until PHP5.3. Imagine this scenario. Somebody has their website with code like that checking passwords, running fine since PHP 5.0.1. They **know** that you can't pass an array into a password form field so why would they even check for an array? The code works under 5.2. The deveoper goes to bed. Overnight, the website hoster upgrades PHP to 5.3. Next day, developer logs in. Everything works fine. What's the problem? No problem! Except that if somebody passes an array in to the password field, it will match any possible string. Unless the developer specifically tests trying to log in with an array for a password, they will not notice that their code is now broken by the PHP update. strcmp is doing something wrong, it is returning zero (or zeroey?) when the strings don't match. It didn't do this until PHP 5.3. This is why you can't trust PHP. You just never know what is going to happen.<|eoopr|><|eols|><|endoftext|>
8
lolphp
MiyatodukenMiyamaap
ckgakaw
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|sor|>I was going to point out that the manual warns you to use === with strcmp() for this very reason... but it turns out it doesn't.<|eor|><|eols|><|endoftext|>
7
lolphp
fnzp
ckgpkbh
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|sor|>I was going to point out that the manual warns you to use === with strcmp() for this very reason... but it turns out it doesn't.<|eor|><|soopr|>To be fair, it does!* http://php.net/manual/en/function.strcmp.php#113364 * if you count the user contributed comments down the bottom as being part of the manual. Also I decided to see how hard it is to write a strcmp() in PHP. Turns out it's remarkably easy! All you have to do is use the old shell programming trick to check if a variable is empty. PHP can handle the rest! http://3v4l.org/BEoJC <|eoopr|><|eols|><|endoftext|>
7
lolphp
iopq
ckgle1d
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|sor|>Getting it "right" is hard to define if the code is wrong.<|eor|><|sor|>Yes, but of course, [the documentation](http://php.net/manual/en/function.strcmp.php) is even more wronger: > Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. What it doesn't mention is that it [returns **NULL** when you pass an array...](http://3v4l.org/N4hYT#v530) EDIT: [didn't we have that already?](http://danuxx.blogspot.co.uk/2013/03/unauthorized-access-bypassing-php-strcmp.html)<|eor|><|sor|>The documentation says it's for string comparison, why would you pass an array to it?<|eor|><|sor|>you're not the one passing the array to it, the malicious user is there's a "feature" where you can pass arrays to PHP through the query string<|eor|><|eols|><|endoftext|>
7
lolphp
mort96
ckg7dv3
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|sor|>Wouldn't it be a better comparison if the code didn't have dozens of notices and warning? Or does it only do something wrong if your code is wrong and full of errors?<|eor|><|eols|><|endoftext|>
6
lolphp
DoubleNabla
ckg9scj
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|sor|>Getting it "right" is hard to define if the code is wrong.<|eor|><|sor|>Yes, but of course, [the documentation](http://php.net/manual/en/function.strcmp.php) is even more wronger: > Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. What it doesn't mention is that it [returns **NULL** when you pass an array...](http://3v4l.org/N4hYT#v530) EDIT: [didn't we have that already?](http://danuxx.blogspot.co.uk/2013/03/unauthorized-access-bypassing-php-strcmp.html)<|eor|><|eols|><|endoftext|>
6
lolphp
OneWingedShark
ckhmozy
<|sols|><|sot|>They broke strcmp() in php5.3, it used to get it right!<|eot|><|sol|>http://3v4l.org/LE8Jb<|eol|><|sor|>Getting it "right" is hard to define if the code is wrong.<|eor|><|soopr|>Not true. Getting it right when the code is wrong is the easiest: die("YOUR CODE IS WRONG FIX IT OR THIS PROGRAM CAN'T RUN"); This is one of the major problems in PHP. Instead of dying and forcing the programmer to fix the mistakes, it just keeps on trucking. With so many possible ways to make mistakes, this is sure to lead to problems.<|eoopr|><|sor|>> die("YOUR CODE IS WRONG FIX IT OR THIS PROGRAM CAN'T RUN"); I think this could be improved: die( "YOU ARE USING PHP." );<|eor|><|eols|><|endoftext|>
5
lolphp
recaph
1v81xy
<|sols|><|sot|>Switch uses loose comparison<|eot|><|sol|>http://www.php.net/manual/en/control-structures.switch.php<|eol|><|eols|><|endoftext|>
17
lolphp
Porges
cepzxyr
<|sols|><|sot|>Switch uses loose comparison<|eot|><|sol|>http://www.php.net/manual/en/control-structures.switch.php<|eol|><|sor|>From TFM: > Note: Note that unlike some other languages, the `continue` statement applies to switch and acts similar to `break`. If you have a switch inside a loop and wish to continue to the next iteration of the outer loop, use `continue 2`. The content, it writes itself. Also, what does 'similar to' mean? PS: https://eval.in/89743<|eor|><|eols|><|endoftext|>
9
lolphp
recaph
ceqbi53
<|sols|><|sot|>Switch uses loose comparison<|eot|><|sol|>http://www.php.net/manual/en/control-structures.switch.php<|eol|><|soopr|>To clarify, this pretty much means that switch statements are useless, unless you verify the type of the input to the switch. In the following example, I'll try to highlight some of the dangers: https://eval.in/90068 Switch is completely broken, and isn't worth the hassle of having to make sure that type you are sending is correct. It will be much easier, and safer, to just do if-statements using the === operator.<|eoopr|><|eols|><|endoftext|>
7
lolphp
poizan42
1uy0mv
<|soss|><|sot|>DomainException,RangeException,OutOfRangeException and OutOfBoundsException<|eot|><|sost|>So we have these four different exceptions which may or may not be for the same thing: * [DomainException](http://www.php.net/manual/en/class.domainexception.php): Exception thrown if a value does not adhere to a defined valid data domain. * [RangeException](http://www.php.net/manual/en/class.rangeexception.php): Exception thrown to indicate range errors during program execution. Normally this means there was an arithmetic error other than under/overflow. This is the runtime version of DomainException. * [OutOfRangeException](http://www.php.net/manual/en/class.outofrangeexception.php): Exception thrown when an illegal index was requested. This represents errors that should be detected at compile time. * [OutOfBoundsException](http://www.php.net/manual/en/class.outofboundsexception.php): Exception thrown if a value is not a valid key. This represents errors that cannot be detected at compile time. You gotta wonder what "compile time" means for a dynamic language. Also what exactly is an "arithmetic error"? Is that supposed to include simple things like giving a negative value to a function only accepting positive values, or is that a DomainException? What is an invalid value for an enumeration supposed to be? DomainException? Or is it only a DomainException if the programmer supplied the invalid value and a RangeException if the invalid value was supplied by a user, which the functions should somehow magically know? What if the enumeration value is used as an index into an array, is it then an OutOfRangeException too? What about an invalid key to a dictionary? Is that supposed to be an OutOfRangeException if integral and an OutOfBoundsException if non-integral?<|eost|><|eoss|><|endoftext|>
17
lolphp
TheGreatFohl
cemtyru
<|soss|><|sot|>DomainException,RangeException,OutOfRangeException and OutOfBoundsException<|eot|><|sost|>So we have these four different exceptions which may or may not be for the same thing: * [DomainException](http://www.php.net/manual/en/class.domainexception.php): Exception thrown if a value does not adhere to a defined valid data domain. * [RangeException](http://www.php.net/manual/en/class.rangeexception.php): Exception thrown to indicate range errors during program execution. Normally this means there was an arithmetic error other than under/overflow. This is the runtime version of DomainException. * [OutOfRangeException](http://www.php.net/manual/en/class.outofrangeexception.php): Exception thrown when an illegal index was requested. This represents errors that should be detected at compile time. * [OutOfBoundsException](http://www.php.net/manual/en/class.outofboundsexception.php): Exception thrown if a value is not a valid key. This represents errors that cannot be detected at compile time. You gotta wonder what "compile time" means for a dynamic language. Also what exactly is an "arithmetic error"? Is that supposed to include simple things like giving a negative value to a function only accepting positive values, or is that a DomainException? What is an invalid value for an enumeration supposed to be? DomainException? Or is it only a DomainException if the programmer supplied the invalid value and a RangeException if the invalid value was supplied by a user, which the functions should somehow magically know? What if the enumeration value is used as an index into an array, is it then an OutOfRangeException too? What about an invalid key to a dictionary? Is that supposed to be an OutOfRangeException if integral and an OutOfBoundsException if non-integral?<|eost|><|sor|>I have no clue what the exceptions mean, but I can tell you what compile time means for PHP: PHP files get translated to OP-code that is then run by the interpreter. In standard settings this happens every time the file is executed. Edit: Now that I think about it more though... How are you supposed to catch exceptions during compile time? That doesn't seem possible to me.... Oh well, I guess that's just PHP for ya.<|eor|><|eoss|><|endoftext|>
6
lolphp
shoghicp
16477d
<|sols|><|sot|>At the Limits of PHP - Minecraft Pocket Edition UDP Server - Pure PHP<|eot|><|sol|>http://shoghicp.github.com/PocketMine-MP/<|eol|><|eols|><|endoftext|>
17
lolphp
ealf
g2wcv
<|sols|><|sot|>I nominate this function for the Orthogonal API Design Award.<|eot|><|sol|>http://www.php.net/manual/en/function.gzgetss.php<|eol|><|eols|><|endoftext|>
20
lolphp
ealf
qgshpr
<|sols|><|sot|>PHP 8 fixes ('foo' == 0), but keeps md5("FfHd0M7m") == 0<|eot|><|sol|>https://wiki.php.net/rfc/string_to_number_comparison<|eol|><|eols|><|endoftext|>
17
lolphp
colshrapnel
hi86bas
<|sols|><|sot|>PHP 8 fixes ('foo' == 0), but keeps md5("FfHd0M7m") == 0<|eot|><|sol|>https://wiki.php.net/rfc/string_to_number_comparison<|eol|><|sor|>uh oh what a blunder. "I run into the mud but it's Nike to blame that my sneakers are now soled!" In case you don't get it, 0e476654702450299632468777628354 is a legit scientific notation that is effectively equals to zero. Besides, nobody forced you to use the loose comparison.<|eor|><|eols|><|endoftext|>
20
lolphp
barubary
hi89ya9
<|sols|><|sot|>PHP 8 fixes ('foo' == 0), but keeps md5("FfHd0M7m") == 0<|eot|><|sol|>https://wiki.php.net/rfc/string_to_number_comparison<|eol|><|sor|>uh oh what a blunder. "I run into the mud but it's Nike to blame that my sneakers are now soled!" In case you don't get it, 0e476654702450299632468777628354 is a legit scientific notation that is effectively equals to zero. Besides, nobody forced you to use the loose comparison.<|eor|><|sor|>> Besides, nobody forced you to use the loose comparison. PHP did. Quoting from the linked article: > The single largest source of bugs is likely the fact that `0 == "foobar"` returns true. **Quite often this is encountered in cases where the comparison is implicit, such as `in_array()` or switch statements.**<|eor|><|eols|><|endoftext|>
16
lolphp
TinStingray
hi8qzxn
<|sols|><|sot|>PHP 8 fixes ('foo' == 0), but keeps md5("FfHd0M7m") == 0<|eot|><|sol|>https://wiki.php.net/rfc/string_to_number_comparison<|eol|><|sor|>I think this is perfectly reasonable. You wanted a loose comparison and you got one.<|eor|><|eols|><|endoftext|>
12
lolphp
GoTriggerYourself
hicjba8
<|sols|><|sot|>PHP 8 fixes ('foo' == 0), but keeps md5("FfHd0M7m") == 0<|eot|><|sol|>https://wiki.php.net/rfc/string_to_number_comparison<|eol|><|sor|>uh oh what a blunder. "I run into the mud but it's Nike to blame that my sneakers are now soled!" In case you don't get it, 0e476654702450299632468777628354 is a legit scientific notation that is effectively equals to zero. Besides, nobody forced you to use the loose comparison.<|eor|><|sor|>> Besides, nobody forced you to use the loose comparison. Why are you defending insecure by default?<|eor|><|eols|><|endoftext|>
8
lolphp
TinStingray
hic105t
<|sols|><|sot|>PHP 8 fixes ('foo' == 0), but keeps md5("FfHd0M7m") == 0<|eot|><|sol|>https://wiki.php.net/rfc/string_to_number_comparison<|eol|><|sor|>I think this is perfectly reasonable. You wanted a loose comparison and you got one.<|eor|><|sor|>Loose comparisons are for things like 0 == "0", not absurd things like 'foo' == 0.<|eor|><|sor|>Once you introduce the idea of "truthiness" like that, all bets are off.<|eor|><|eols|><|endoftext|>
8
lolphp
colshrapnel
hi8au3a
<|sols|><|sot|>PHP 8 fixes ('foo' == 0), but keeps md5("FfHd0M7m") == 0<|eot|><|sol|>https://wiki.php.net/rfc/string_to_number_comparison<|eol|><|sor|>uh oh what a blunder. "I run into the mud but it's Nike to blame that my sneakers are now soled!" In case you don't get it, 0e476654702450299632468777628354 is a legit scientific notation that is effectively equals to zero. Besides, nobody forced you to use the loose comparison.<|eor|><|sor|>> Besides, nobody forced you to use the loose comparison. PHP did. Quoting from the linked article: > The single largest source of bugs is likely the fact that `0 == "foobar"` returns true. **Quite often this is encountered in cases where the comparison is implicit, such as `in_array()` or switch statements.**<|eor|><|sor|>> PHP did. But not anymore. > strict > If the third parameter strict is set to true then the in_array() function will also check the types of the needle in the haystack. and > A match arm compares values strictly (===) instead of loosely as the switch statement does.<|eor|><|eols|><|endoftext|>
6
lolphp
CarnivorousSociety
hic79ra
<|sols|><|sot|>PHP 8 fixes ('foo' == 0), but keeps md5("FfHd0M7m") == 0<|eot|><|sol|>https://wiki.php.net/rfc/string_to_number_comparison<|eol|><|sor|>Why would you use == for that in the first place ?<|eor|><|sor|>I still maintain 99% of all lolphp and php issues are based upon implicit type conversions happening when the programmer doesn't realize. Whether this is bad language design or bad programmers is up for debate and both have merits in various cases.<|eor|><|eols|><|endoftext|>
5
lolphp
barubary
hi8ko9y
<|sols|><|sot|>PHP 8 fixes ('foo' == 0), but keeps md5("FfHd0M7m") == 0<|eot|><|sol|>https://wiki.php.net/rfc/string_to_number_comparison<|eol|><|sor|>uh oh what a blunder. "I run into the mud but it's Nike to blame that my sneakers are now soled!" In case you don't get it, 0e476654702450299632468777628354 is a legit scientific notation that is effectively equals to zero. Besides, nobody forced you to use the loose comparison.<|eor|><|sor|>> Besides, nobody forced you to use the loose comparison. PHP did. Quoting from the linked article: > The single largest source of bugs is likely the fact that `0 == "foobar"` returns true. **Quite often this is encountered in cases where the comparison is implicit, such as `in_array()` or switch statements.**<|eor|><|sor|>> PHP did. But not anymore. > strict > If the third parameter strict is set to true then the in_array() function will also check the types of the needle in the haystack. and > A match arm compares values strictly (===) instead of loosely as the switch statement does.<|eor|><|sor|>Does this also fix `>`, `>=`, and friends?<|eor|><|eols|><|endoftext|>
5
lolphp
Mark_Messa
dn7g96
<|soss|><|sot|>PHP gc_probability/gc_divisor<|eot|><|sost|>According to [PHP Manual](https://www.php.net/manual/en/session.configuration.php#ini.session.gc-probability): > **session.gc_probability** > session.gc_probability in conjunction with session.gc_divisor is used to manage probability that the gc (garbage collection) routine is started. > &nbsp; > **session.gc_divisor** > session.gc_divisor coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. &nbsp; Why not only one parameter instead? Ex: `session.gc_percent = 1%`<|eost|><|eoss|><|endoftext|>
18
lolphp
the_alias_of_andrea
f59whew
<|soss|><|sot|>PHP gc_probability/gc_divisor<|eot|><|sost|>According to [PHP Manual](https://www.php.net/manual/en/session.configuration.php#ini.session.gc-probability): > **session.gc_probability** > session.gc_probability in conjunction with session.gc_divisor is used to manage probability that the gc (garbage collection) routine is started. > &nbsp; > **session.gc_divisor** > session.gc_divisor coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. &nbsp; Why not only one parameter instead? Ex: `session.gc_percent = 1%`<|eost|><|sor|>PHP gc is a huge lol. Anon functions (the ones created by create_function) are never gcd. There was a discussion some years ago to remove gc alltogherer, because the way php works (start and die immediately) there was no need for gc. That was a huge lol of a discussion.<|eor|><|sor|>> Anon functions (the ones created by create_function) are never gcd. Maybe there's a reason that create_function is deprecated and you are encouraged to use closures, which are vastly superior and have existed in PHP for ten years? > There was a discussion some years ago to remove gc alltogherer, because the way php works (start and die immediately) there was no need for gc. PHP's GC is purely a cycle collector. If you disable it with `gc_disable();`, memory still gets freed automatically, except where there are cycles. For some applications that could be enough.<|eor|><|sor|>PHP closures are so nasty and unpleasent to use its unreal. PHP is never really running at all, so there could be memory leaks all over the place. In PHPs case these bugs are rarely reported because of the nature of php. The GC is mostly a joke, so i understand why some wanted to remove it.<|eor|><|sor|>> PHP is never really running at all, so there could be memory leaks all over the place. What does this even mean? > The GC is mostly a joke How so?<|eor|><|eoss|><|endoftext|>
7
lolphp
fast4shoot
f598uc2
<|soss|><|sot|>PHP gc_probability/gc_divisor<|eot|><|sost|>According to [PHP Manual](https://www.php.net/manual/en/session.configuration.php#ini.session.gc-probability): > **session.gc_probability** > session.gc_probability in conjunction with session.gc_divisor is used to manage probability that the gc (garbage collection) routine is started. > &nbsp; > **session.gc_divisor** > session.gc_divisor coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. &nbsp; Why not only one parameter instead? Ex: `session.gc_percent = 1%`<|eost|><|sor|>Meh, there's some value in using two ints as a fraction instead of floating point numbers when dealing with fractions. Though I wouldn't say it applies here.<|eor|><|eoss|><|endoftext|>
6
lolphp
the_alias_of_andrea
f59m5mk
<|soss|><|sot|>PHP gc_probability/gc_divisor<|eot|><|sost|>According to [PHP Manual](https://www.php.net/manual/en/session.configuration.php#ini.session.gc-probability): > **session.gc_probability** > session.gc_probability in conjunction with session.gc_divisor is used to manage probability that the gc (garbage collection) routine is started. > &nbsp; > **session.gc_divisor** > session.gc_divisor coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. &nbsp; Why not only one parameter instead? Ex: `session.gc_percent = 1%`<|eost|><|sor|>PHP gc is a huge lol. Anon functions (the ones created by create_function) are never gcd. There was a discussion some years ago to remove gc alltogherer, because the way php works (start and die immediately) there was no need for gc. That was a huge lol of a discussion.<|eor|><|sor|>> Anon functions (the ones created by create_function) are never gcd. Maybe there's a reason that create_function is deprecated and you are encouraged to use closures, which are vastly superior and have existed in PHP for ten years? > There was a discussion some years ago to remove gc alltogherer, because the way php works (start and die immediately) there was no need for gc. PHP's GC is purely a cycle collector. If you disable it with `gc_disable();`, memory still gets freed automatically, except where there are cycles. For some applications that could be enough.<|eor|><|eoss|><|endoftext|>
6
lolphp
barubary
f598i61
<|soss|><|sot|>PHP gc_probability/gc_divisor<|eot|><|sost|>According to [PHP Manual](https://www.php.net/manual/en/session.configuration.php#ini.session.gc-probability): > **session.gc_probability** > session.gc_probability in conjunction with session.gc_divisor is used to manage probability that the gc (garbage collection) routine is started. > &nbsp; > **session.gc_divisor** > session.gc_divisor coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. &nbsp; Why not only one parameter instead? Ex: `session.gc_percent = 1%`<|eost|><|sor|>PHP gc is a huge lol. Anon functions (the ones created by create_function) are never gcd. There was a discussion some years ago to remove gc alltogherer, because the way php works (start and die immediately) there was no need for gc. That was a huge lol of a discussion.<|eor|><|sor|>This is about sessions, not memory.<|eor|><|eoss|><|endoftext|>
6
lolphp
Takeoded
dekmu1
<|soss|><|sot|>socket_accept() returns false on error<|eot|><|sost|>[documentation](https://www.php.net/manual/en/function.socket-accept.php) says: > Returns a new socket resource on success, or FALSE on error. The actual error code can be retrieved by calling socket_last_error(). This error code may be passed to socket_strerror() to get a textual explanation of the error. and testing it, we get: ```sh $ php -r 'var_dump(socket_accept(false));' PHP Warning: socket_accept() expects parameter 1 to be resource, bool given in Command line code on line 1 NULL ``` NULL for some types of bogus arguments, ```sh $ php -r 'var_dump(socket_accept(curl_init()));' PHP Warning: socket_accept(): supplied resource is not a valid Socket resource in Command line code on line 1 bool(false) ``` and bool(false) for other types of bogus arguments..<|eost|><|eoss|><|endoftext|>
16
lolphp
Takeoded
f2wtbk0
<|soss|><|sot|>socket_accept() returns false on error<|eot|><|sost|>[documentation](https://www.php.net/manual/en/function.socket-accept.php) says: > Returns a new socket resource on success, or FALSE on error. The actual error code can be retrieved by calling socket_last_error(). This error code may be passed to socket_strerror() to get a textual explanation of the error. and testing it, we get: ```sh $ php -r 'var_dump(socket_accept(false));' PHP Warning: socket_accept() expects parameter 1 to be resource, bool given in Command line code on line 1 NULL ``` NULL for some types of bogus arguments, ```sh $ php -r 'var_dump(socket_accept(curl_init()));' PHP Warning: socket_accept(): supplied resource is not a valid Socket resource in Command line code on line 1 bool(false) ``` and bool(false) for other types of bogus arguments..<|eost|><|sor|>I can only wonder what the php code for this function looks like.. I'm sure it is littered with return statements<|eor|><|sor|>It's pretty simple: https://github.com/php/php-src/blob/5d6e923d46a89fe9cd8fb6c3a6da675aa67197b4/ext/sockets/sockets.c#L1046-L1066 So here it checks if arg1 is of the type resource: if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &arg1) == FAILURE) { return; } false is not a resource, so this returns NULL for OPs first example. Then (I assume, don't know a lot about php internals), it casts the resource to a php_socket and then tries to accept the connection. if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { RETURN_FALSE; } if (!php_accept_connect(php_sock, &new_sock, (struct sockaddr*)&sa, &php_sa_len)) { RETURN_FALSE; } Both of these should fail, so that's why the second example returns false. Because curl_init() returns a resource, but can't be cast to a php_socket or accept the connection. So to sum up, socket_accept returns NULL if called with a argument that is not of the type resource. If the resource isn't a php_socket or if it can't accept the connection it returns false.<|eor|><|sor|>It's still an lolphp because it's not documented that it returns NULL at all unless I'm missing something<|eor|><|soopr|>bingo! it actually broke my code doing a while(false!==($conn=socket_accept($srv))){...} it became an infinite error loop rather than exiting on errors because socket\_accept kept returning NULL instead of false <.<<|eoopr|><|eoss|><|endoftext|>
8
lolphp
nikic
f2x5go9
<|soss|><|sot|>socket_accept() returns false on error<|eot|><|sost|>[documentation](https://www.php.net/manual/en/function.socket-accept.php) says: > Returns a new socket resource on success, or FALSE on error. The actual error code can be retrieved by calling socket_last_error(). This error code may be passed to socket_strerror() to get a textual explanation of the error. and testing it, we get: ```sh $ php -r 'var_dump(socket_accept(false));' PHP Warning: socket_accept() expects parameter 1 to be resource, bool given in Command line code on line 1 NULL ``` NULL for some types of bogus arguments, ```sh $ php -r 'var_dump(socket_accept(curl_init()));' PHP Warning: socket_accept(): supplied resource is not a valid Socket resource in Command line code on line 1 bool(false) ``` and bool(false) for other types of bogus arguments..<|eost|><|sor|>This will be comprehensively fixed in PHP 8 with https://wiki.php.net/rfc/consistent_type_errors. Both of those will throw `TypeError`.<|eor|><|eoss|><|endoftext|>
5
lolphp
phplovesong
cvla8i
<|sols|><|sot|>Vote for PHP++ was rejected 0-52. Not even to original "designer" voted for it.<|eot|><|sol|>https://wiki.php.net/rfc/p-plus-plus<|eol|><|eols|><|endoftext|>
17
lolphp
shitcanz
ey4xkvh
<|sols|><|sot|>Vote for PHP++ was rejected 0-52. Not even to original "designer" voted for it.<|eot|><|sol|>https://wiki.php.net/rfc/p-plus-plus<|eol|><|sor|>This was a hilarious vote. PHP seems to be in a kind of dead zone. PHP has neither a vision or a future plan. It seems some core devs want to make it more typed (like java) and so far there is all these weird things you must orchestrate to have types (declare strict types header etc) That said, PHP types are really poor. Trying to compare PHP types to ANY other language with types PHP falls short. The other camp wants to freeze all PHP development and keep it relatively unchanged. This is a good solution for PHP as there is really no need to further develop this language. If this was the case PHP would have BC for year to come. All the CMS systems could keep going and legacy apps would still be able to utilize newer PHP versions. Again, the language would not evolve but stay as it has for years. In PHPs case this would actually be a good thing. Finally the last part of core devs seem to just be silent and have all but abandoned PHP for saner languages.<|eor|><|eols|><|endoftext|>
13
lolphp
skawid
8lszl2
<|soss|><|sot|>I thought we were past this<|eot|><|sost|> <?php var_dump(array(0 => ':p1') == array(0 => 0)); // bool(true) Ten years and this language is still finding ways to kick me in the nuts. I mean, I get it. An array is equal if its keys and elements are equal. And `:p1` is, in the PHP sense, equal to 0. But still.<|eost|><|eoss|><|endoftext|>
17