subreddit
stringclasses 7
values | author
stringlengths 3
20
| id
stringlengths 5
7
| content
stringlengths 67
30.4k
| score
int64 0
140k
|
---|---|---|---|---|
lolphp
|
berkes
|
cffxjbi
|
<|sols|><|sot|>"Reading two form elements with same name" - that's an interesting problem, PHP has you covered!<|eot|><|sol|>http://stackoverflow.com/questions/5643981/reading-two-form-elements-with-same-name<|eol|><|sor|>Wrong subreddit surely? Why is this here?<|eor|><|sor|>The HTTP and HTML specs all say it should be considered a list when a name is used multiple times.
Most languages or libs dealing with http-interaction (web applications) will, therefore handle them as lists (hashes, tuples, arrays or whatnot). But not PHP, whis has but one focus: http/HTML interaction.<|eor|><|eols|><|endoftext|>
| 10 |
lolphp
|
mck1117
|
cffvw5o
|
<|sols|><|sot|>"Reading two form elements with same name" - that's an interesting problem, PHP has you covered!<|eot|><|sol|>http://stackoverflow.com/questions/5643981/reading-two-form-elements-with-same-name<|eol|><|sor|>You can also give an index to the array (string or number), so technically they *don't* have the same name, but to PHP they're still in the same array or input values:
Name: <input type="text" name="fname[0]" />
<input type="hidden" name="fname[1]" value="test" />
or
Name: <input type="text" name="fname[text]" />
<input type="hidden" name="fname[hidden]" value="test" />
<|eor|><|sor|>The OP in the SO article insisted they can't be an array. It's like he's asking how to put a nail in a board, and everyone is showing him a variety of hammers, but he insists on using a spoon. <|eor|><|sor|>The spoon's name? PHP.<|eor|><|eols|><|endoftext|>
| 7 |
lolphp
|
Matt3k
|
cffpv32
|
<|sols|><|sot|>"Reading two form elements with same name" - that's an interesting problem, PHP has you covered!<|eot|><|sol|>http://stackoverflow.com/questions/5643981/reading-two-form-elements-with-same-name<|eol|><|sor|>Well that's annoying if you want it to be an array with one item.<|eor|><|sor|>Yeah, I see your point. There really is no optimal solution. Null separators suck, changing form input names sucks, etc. Of all the solutions, I prefer this one the best (or none at all). <|eor|><|sor|>I really don't see the problem with the "var-name[]" format. Ruby on Rails handles form fields the same way. It's also very convenient if you dynamically add form elements via JS (think a list of items with add/remove buttons) - you don't have to worry about creating a unique name attribute for each item.<|eor|><|sor|>You're assuming the HTML is completely under your control. <|eor|><|sor|>A fair assumption to make if you're the developer. Even if there's a different guy doing the frontend, just email/call/text/skype him to get his form fields sorted.<|eor|><|sor|>What if there's not a "guy" doing the front end? What if it's coming from some kind of automated process? What if there's Javascript tied into the form field names and that isn't under your control either? You know what's best? Having a server side which handles HTML forms correctly.<|eor|><|sor|>Get it under your control.
If you're handling form input, the form should be your domain.
Maybe the automated processes need to be updated, maybe the javascript needs to be improved, maybe PHP wasn't the right language choice.
If the forms are an issue, it'll need to get resolved. Blaming PHP because it behaves differently from ASP.Net isn't going to help.<|eor|><|sor|>> If you're handling form input, the form should be your domain.
That is not practical in many situations. Let me just pull an example out of the air. Paypal will submit name/value pairs back to your application via HTTP post. Do you think they're going to give you any control over that process?
In many cases, checkboxes being the primary example offered up in this thread, it is perfectly reasonable to have multiple input elements with the same name. It's legal syntax. Forcing your HTML to bend to the needs of the back end framework is a basic design error.
However I strongly suspect the issue is largely moot. There is almost certainly a way to read the raw data being posted to the PHP script. You might have to parse it manually, but I am positive it is possible.<|eor|><|eols|><|endoftext|>
| 7 |
lolphp
|
bart2019
|
cffdpe9
|
<|sols|><|sot|>"Reading two form elements with same name" - that's an interesting problem, PHP has you covered!<|eot|><|sol|>http://stackoverflow.com/questions/5643981/reading-two-form-elements-with-same-name<|eol|><|sor|>You can also give an index to the array (string or number), so technically they *don't* have the same name, but to PHP they're still in the same array or input values:
Name: <input type="text" name="fname[0]" />
<input type="hidden" name="fname[1]" value="test" />
or
Name: <input type="text" name="fname[text]" />
<input type="hidden" name="fname[hidden]" value="test" />
<|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
until0
|
cffh818
|
<|sols|><|sot|>"Reading two form elements with same name" - that's an interesting problem, PHP has you covered!<|eot|><|sol|>http://stackoverflow.com/questions/5643981/reading-two-form-elements-with-same-name<|eol|><|sor|>Well, to be fair, other frameworks have made similar features (Dancer) that are nice, but I suppose it's silly as part of the language.
I should note though, Dancer doesn't do the stupid [] in form names though. Just if you have two fields with same name, it will automatically convert them into a list ref. <|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
ANAL_GRAVY
|
cffe9f2
|
<|sols|><|sot|>"Reading two form elements with same name" - that's an interesting problem, PHP has you covered!<|eot|><|sol|>http://stackoverflow.com/questions/5643981/reading-two-form-elements-with-same-name<|eol|><|sor|>It's such a beautiful feature.
[PHP Vulnerability May Halt Millions of Servers](http://www.phpclasses.org/blog/post/171-PHP-Vulnerability-May-Halt-Millions-of-Servers.html)
Just one of many example exploits you can [find](https://www.google.co.uk/search?q=php+form+array+exploit)<|eor|><|sor|>The first link is a unrelated potential vulnerability, but was fixed in 5.3.9 anyway. If you're running old versions of PHP (at least 2 years old), and allowing your PHP scripts to run for eternity, and running on a public server without the Suhosin extension, you're asking for trouble!
The second is only an exploit if you're not aware of the feature. It's actually really quite handy. You should really be sanitising your inputs, anyway.<|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
cwmonkey
|
cffkys1
|
<|sols|><|sot|>"Reading two form elements with same name" - that's an interesting problem, PHP has you covered!<|eot|><|sol|>http://stackoverflow.com/questions/5643981/reading-two-form-elements-with-same-name<|eol|><|sor|>Wrong subreddit surely? Why is this here?<|eor|><|sor|>Users of other languages find this hilarious because every other language I can think of automatically converts posted variables with the same name to arrays without having to use the [] gimmicks.<|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
mellett68
|
cffi60e
|
<|sols|><|sot|>"Reading two form elements with same name" - that's an interesting problem, PHP has you covered!<|eot|><|sol|>http://stackoverflow.com/questions/5643981/reading-two-form-elements-with-same-name<|eol|><|sor|>It's such a beautiful feature.
[PHP Vulnerability May Halt Millions of Servers](http://www.phpclasses.org/blog/post/171-PHP-Vulnerability-May-Halt-Millions-of-Servers.html)
Just one of many example exploits you can [find](https://www.google.co.uk/search?q=php+form+array+exploit)<|eor|><|sor|>The first link is a unrelated potential vulnerability, but was fixed in 5.3.9 anyway. If you're running old versions of PHP (at least 2 years old), and allowing your PHP scripts to run for eternity, and running on a public server without the Suhosin extension, you're asking for trouble!
The second is only an exploit if you're not aware of the feature. It's actually really quite handy. You should really be sanitising your inputs, anyway.<|eor|><|sor|>> f you're running old versions of PHP (at least 2 years old), and allowing your PHP scripts to run for eternity, and running on a public server without the Suhosin extension, you're asking for trouble!
So every RHEL/CentOS server, then?<|eor|><|sor|>Don't forget Ubuntu LTS<|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
seriouslulz
|
1w2fwa
|
<|sols|><|sot|>Syntax Horror (French website but the code is pretty self-explanatory)<|eot|><|sol|>http://syntaxhorror.com/-php-<|eol|><|eols|><|endoftext|>
| 10 |
lolphp
|
catcradle5
|
cey6rgb
|
<|sols|><|sot|>Syntax Horror (French website but the code is pretty self-explanatory)<|eot|><|sol|>http://syntaxhorror.com/-php-<|eol|><|sor|>>Parce que fuck foreach et fuck $_POST
I like how "fuck" is a universal term, even in other languages.<|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
Ghosty141
|
ml9wb4
|
<|soss|><|sot|>kilobyte, kibibyte, who cares!<|eot|><|sost|>https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
>Note: kilobyte versus kibibyte
>The PHP notation describes one kilobyte as equalling 1024 bytes, whereas the IEC standard considers this to be a kibibyte instead. Summary: k and K = 1024 bytes.<|eost|><|eoss|><|endoftext|>
| 10 |
lolphp
|
keis
|
gtkd0nl
|
<|soss|><|sot|>kilobyte, kibibyte, who cares!<|eot|><|sost|>https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
>Note: kilobyte versus kibibyte
>The PHP notation describes one kilobyte as equalling 1024 bytes, whereas the IEC standard considers this to be a kibibyte instead. Summary: k and K = 1024 bytes.<|eost|><|sor|>up until somewhere around year 2000, kilobyte was almost exclusively understood to mean 1024 even with the kilo prefix. Even today many people and output of tools will talk about of Kb when they mean KiBI.
Not surprising something like php that predates the proper terminology catching on sticking with it to avoid breaking backwards compatibility.
more like lol "computer science" for thinking calling 1024 kilo was a good idea to start with :D<|eor|><|eoss|><|endoftext|>
| 29 |
lolphp
|
Muzer0
|
gtkhu90
|
<|soss|><|sot|>kilobyte, kibibyte, who cares!<|eot|><|sost|>https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
>Note: kilobyte versus kibibyte
>The PHP notation describes one kilobyte as equalling 1024 bytes, whereas the IEC standard considers this to be a kibibyte instead. Summary: k and K = 1024 bytes.<|eost|><|sor|>up until somewhere around year 2000, kilobyte was almost exclusively understood to mean 1024 even with the kilo prefix. Even today many people and output of tools will talk about of Kb when they mean KiBI.
Not surprising something like php that predates the proper terminology catching on sticking with it to avoid breaking backwards compatibility.
more like lol "computer science" for thinking calling 1024 kilo was a good idea to start with :D<|eor|><|sor|>I once saw a document from the 80s that says "kB" means 1000 bytes and "KB" means 1024 bytes. This obviously didn't catch on for long as it wouldn't work with MB, but I thought it was a nice idea for the time.<|eor|><|soopr|>This is still around. MB = MiB = Mebibyte, for example. It's just that nobody uses these terms in day to day use. Professionals tend to use them more often.<|eoopr|><|sor|>Um, but mB doesn't mean 1000000 bytes, it means 0.001 bytes. My point was the "k" vs "K" distinction is unique to kilo/kibi, and can't be applied to other multiples.<|eor|><|eoss|><|endoftext|>
| 7 |
lolphp
|
Muzer0
|
gtkfeg4
|
<|soss|><|sot|>kilobyte, kibibyte, who cares!<|eot|><|sost|>https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
>Note: kilobyte versus kibibyte
>The PHP notation describes one kilobyte as equalling 1024 bytes, whereas the IEC standard considers this to be a kibibyte instead. Summary: k and K = 1024 bytes.<|eost|><|sor|>up until somewhere around year 2000, kilobyte was almost exclusively understood to mean 1024 even with the kilo prefix. Even today many people and output of tools will talk about of Kb when they mean KiBI.
Not surprising something like php that predates the proper terminology catching on sticking with it to avoid breaking backwards compatibility.
more like lol "computer science" for thinking calling 1024 kilo was a good idea to start with :D<|eor|><|sor|>I once saw a document from the 80s that says "kB" means 1000 bytes and "KB" means 1024 bytes. This obviously didn't catch on for long as it wouldn't work with MB, but I thought it was a nice idea for the time.<|eor|><|eoss|><|endoftext|>
| 6 |
lolphp
|
Ghosty141
|
gtkfv63
|
<|soss|><|sot|>kilobyte, kibibyte, who cares!<|eot|><|sost|>https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
>Note: kilobyte versus kibibyte
>The PHP notation describes one kilobyte as equalling 1024 bytes, whereas the IEC standard considers this to be a kibibyte instead. Summary: k and K = 1024 bytes.<|eost|><|sor|>up until somewhere around year 2000, kilobyte was almost exclusively understood to mean 1024 even with the kilo prefix. Even today many people and output of tools will talk about of Kb when they mean KiBI.
Not surprising something like php that predates the proper terminology catching on sticking with it to avoid breaking backwards compatibility.
more like lol "computer science" for thinking calling 1024 kilo was a good idea to start with :D<|eor|><|sor|>I once saw a document from the 80s that says "kB" means 1000 bytes and "KB" means 1024 bytes. This obviously didn't catch on for long as it wouldn't work with MB, but I thought it was a nice idea for the time.<|eor|><|soopr|>This is still around. MB = MiB = Mebibyte, for example. It's just that nobody uses these terms in day to day use. Professionals tend to use them more often.<|eoopr|><|eoss|><|endoftext|>
| 5 |
lolphp
|
Jinxuan
|
fdh77z
|
<|soss|><|sot|>array to string is a warning, while object to string is an error<|eot|><|sost|>Though neither array nor object can be converted to string, they still behaves differently in string conversion.
```
$x = (string) []; // PHP notice: Array to string conversion
var_dump($x); // $x is an array; not string
$y = (string) (new stdClass); // PHP Error: Object of class stdClass could not be converted to string
isset($y); // $y is not set
```<|eost|><|eoss|><|endoftext|>
| 9 |
lolphp
|
barubary
|
fjkb0a4
|
<|soss|><|sot|>array to string is a warning, while object to string is an error<|eot|><|sost|>Though neither array nor object can be converted to string, they still behaves differently in string conversion.
```
$x = (string) []; // PHP notice: Array to string conversion
var_dump($x); // $x is an array; not string
$y = (string) (new stdClass); // PHP Error: Object of class stdClass could not be converted to string
isset($y); // $y is not set
```<|eost|><|sor|>On the other hand, array to number is an error while object to number is just a warning: /r/lolphp/comments/d9lhpz/the_consistent_behavior_of_unary_plus/<|eor|><|eoss|><|endoftext|>
| 6 |
lolphp
|
Takeoded
|
8e1mrv
|
<|soss|><|sot|>TCP socket is both connected and not connected at the same time.<|eot|><|sost|>i'd showcase this in a php testbed (ala 3v4l.org ) if i could, but the only public php testbed allowing network connections that i know of, codepad.viper-7.com , has shut down, so i can't.
try running
<?php
error_reporting ( E_ALL );
$sock = socket_create ( AF_INET, SOCK_STREAM, SOL_TCP );
for($i = 0; $i < 100; ++ $i) {
socket_connect ( $sock, '8.8.8.8', 443 );
socket_shutdown ( $sock, 2 );
}
socket_close ( $sock );
and you'll probably end up with something like
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
>
- where socket_connect complains that it's already connected, and socket_shutdown complains that it's not connected. lovely<|eost|><|eoss|><|endoftext|>
| 10 |
lolphp
|
myaut
|
dxrv9al
|
<|soss|><|sot|>TCP socket is both connected and not connected at the same time.<|eot|><|sost|>i'd showcase this in a php testbed (ala 3v4l.org ) if i could, but the only public php testbed allowing network connections that i know of, codepad.viper-7.com , has shut down, so i can't.
try running
<?php
error_reporting ( E_ALL );
$sock = socket_create ( AF_INET, SOCK_STREAM, SOL_TCP );
for($i = 0; $i < 100; ++ $i) {
socket_connect ( $sock, '8.8.8.8', 443 );
socket_shutdown ( $sock, 2 );
}
socket_close ( $sock );
and you'll probably end up with something like
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
>
- where socket_connect complains that it's already connected, and socket_shutdown complains that it's not connected. lovely<|eost|><|sor|>More like lolunix, as I get same effect in Python \(both are probably simply mapping errnos they get from system calls\). I think this is reasonable in TCP to prevent you from re\-using same source and remote addresses to prevent you from tricking remote side that you still holding a connection \(which actually you reopened\). Of course, you're protected from it because it'll fail in second handshake attempt, but still useful.<|eor|><|eoss|><|endoftext|>
| 14 |
lolphp
|
AyrA_ch
|
dxrzlas
|
<|soss|><|sot|>TCP socket is both connected and not connected at the same time.<|eot|><|sost|>i'd showcase this in a php testbed (ala 3v4l.org ) if i could, but the only public php testbed allowing network connections that i know of, codepad.viper-7.com , has shut down, so i can't.
try running
<?php
error_reporting ( E_ALL );
$sock = socket_create ( AF_INET, SOCK_STREAM, SOL_TCP );
for($i = 0; $i < 100; ++ $i) {
socket_connect ( $sock, '8.8.8.8', 443 );
socket_shutdown ( $sock, 2 );
}
socket_close ( $sock );
and you'll probably end up with something like
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
>
- where socket_connect complains that it's already connected, and socket_shutdown complains that it's not connected. lovely<|eost|><|sor|>More like lolunix, as I get same effect in Python \(both are probably simply mapping errnos they get from system calls\). I think this is reasonable in TCP to prevent you from re\-using same source and remote addresses to prevent you from tricking remote side that you still holding a connection \(which actually you reopened\). Of course, you're protected from it because it'll fail in second handshake attempt, but still useful.<|eor|><|sor|>> More like lolunix
No, this is just how sockets work and applies to windows too. Using shutdown just disables send and/or receive operations but will not disconnect the socket. See Remarks section of this: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740481(v=vs.85).aspx
Using disconnect (on windows at least) allows you to supply a parameter to reuse the same socket<|eor|><|eoss|><|endoftext|>
| 12 |
lolphp
|
shaql
|
dxsfw7n
|
<|soss|><|sot|>TCP socket is both connected and not connected at the same time.<|eot|><|sost|>i'd showcase this in a php testbed (ala 3v4l.org ) if i could, but the only public php testbed allowing network connections that i know of, codepad.viper-7.com , has shut down, so i can't.
try running
<?php
error_reporting ( E_ALL );
$sock = socket_create ( AF_INET, SOCK_STREAM, SOL_TCP );
for($i = 0; $i < 100; ++ $i) {
socket_connect ( $sock, '8.8.8.8', 443 );
socket_shutdown ( $sock, 2 );
}
socket_close ( $sock );
and you'll probably end up with something like
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
> PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected
> PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected
>
- where socket_connect complains that it's already connected, and socket_shutdown complains that it's not connected. lovely<|eost|><|sor|>>`socket_connect ( $sock, '8.8.8.8', 443 );`
Using Cloudflare's [1.1.1.1](https://1.1.1.1/) (and 1.0.0.1 instead of 8.8.4.4) is better for privacy.<|eor|><|sor|>depends whether you trust Corporation B more than Corporation A.<|eor|><|eoss|><|endoftext|>
| 7 |
lolphp
|
6f944ee6
|
5i5rac
|
<|sols|><|sot|>value should be converted to a boolean correctly when non-empty string is passed to it<|eot|><|sol|>https://github.com/php/php-src/pull/2240<|eol|><|eols|><|endoftext|>
| 12 |
lolphp
|
ZiggyTheHamster
|
db5tkgf
|
<|sols|><|sot|>value should be converted to a boolean correctly when non-empty string is passed to it<|eot|><|sol|>https://github.com/php/php-src/pull/2240<|eol|><|sor|>The lolphp is that casting a string with no numbers in it to a long works instead of raising an error.
In basically any other language, if you used `curl_setopt` and passed a bad option value, it would raise an error.<|eor|><|eols|><|endoftext|>
| 7 |
lolphp
|
pilif
|
2q3182
|
<|sols|><|sot|>The mystery of dir()<|eot|><|sol|>http://3v4l.org/a39OP<|eol|><|eols|><|endoftext|>
| 12 |
lolphp
|
Various_Pickles
|
cn2hj42
|
<|sols|><|sot|>The mystery of dir()<|eot|><|sol|>http://3v4l.org/a39OP<|eol|><|soopr|>`dir()` returns something that's not implementing `Traversable`, the interface that, according to [the docs](http://php.net/Traversable) is
> Interface to detect if a class is traversable using foreach.
and yet, you can use foreach() with it.<|eoopr|><|sor|>In PHP, just because something is something by no means guarantees that it is indeed that something.<|eor|><|eols|><|endoftext|>
| 19 |
lolphp
|
pilif
|
cn2c0ex
|
<|sols|><|sot|>The mystery of dir()<|eot|><|sol|>http://3v4l.org/a39OP<|eol|><|soopr|>`dir()` returns something that's not implementing `Traversable`, the interface that, according to [the docs](http://php.net/Traversable) is
> Interface to detect if a class is traversable using foreach.
and yet, you can use foreach() with it.<|eoopr|><|eols|><|endoftext|>
| 5 |
lolphp
|
koro666
|
1srq5h
|
<|sols|><|sot|>eBay remote code execution because PHP parses variable names in certain strings<|eot|><|sol|>http://www.reddit.com/r/netsec/comments/1sqppp/ebay_remotecodeexecution/<|eol|><|eols|><|endoftext|>
| 11 |
lolphp
|
nikic
|
ce14t16
|
<|sols|><|sot|>eBay remote code execution because PHP parses variable names in certain strings<|eot|><|sol|>http://www.reddit.com/r/netsec/comments/1sqppp/ebay_remotecodeexecution/<|eol|><|sor|>Most of the linked article is nonsense, from a technical POV (or maybe just very badly explained). What happened here is simply Ebay running `eval` on user-provided data - hopefully everyone understands how bad that is from a security point of view. (Note: The eval presumably occurred through the /e modifier, not the language construct directly.)<|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
Mattho
|
1l6e7j
|
<|sols|><|sot|>Python generators? compared to other languages<|eot|><|sol|>http://lwn.net/Articles/564871/<|eol|><|eols|><|endoftext|>
| 10 |
lolphp
|
nikic
|
cbwbsqs
|
<|sols|><|sot|>Python generators? compared to other languages<|eot|><|sol|>http://lwn.net/Articles/564871/<|eol|><|sor|>"Generators" are something completely different and have nothing to do with the discussion you linked.<|eor|><|eols|><|endoftext|>
| 29 |
lolphp
|
kageurufu
|
cbwcrxs
|
<|sols|><|sot|>Python generators? compared to other languages<|eot|><|sol|>http://lwn.net/Articles/564871/<|eol|><|sor|>That was list comprehension, a generator would be in parenthesis, instead of brackets.
the reasons to use a generator, would be things like looping through it and breaking at some point. This would lead to not having to calculate every value for memory/efficiency reasons
<|eor|><|eols|><|endoftext|>
| 8 |
lolphp
|
beingryu
|
qmvtp
|
<|soss|><|sot|>Guess the output<|eot|><|sost|> echo(1) and print(2) and die(3); # 2
echo print('3').'2'.print('4'); # 43211
print(1) and print(2) and die(3); # 12 <- edited
Inspired by [this](http://www.reddit.com/r/lolphp/comments/j21bv/guess_the_output_echo1_and_print2_and_die3/) post. Would someone explain these?
edit: third output fixed<|eost|><|eoss|><|endoftext|>
| 10 |
lolphp
|
Rhomboid
|
c3yw0be
|
<|soss|><|sot|>Guess the output<|eot|><|sost|> echo(1) and print(2) and die(3); # 2
echo print('3').'2'.print('4'); # 43211
print(1) and print(2) and die(3); # 12 <- edited
Inspired by [this](http://www.reddit.com/r/lolphp/comments/j21bv/guess_the_output_echo1_and_print2_and_die3/) post. Would someone explain these?
edit: third output fixed<|eost|><|sor|>Neither `print` nor `echo` are real functions but are built-in operators. In the first example, the `(2)` does bind to the print, which would imply that the `print` operator has higher precedence than the `and` operator. But in the second example, the `(3)` does not bind to the `print`, which implies that the `print` operator has lower precedence than the string concatenation operator (`.`). The second one is parsed as if it was:
echo (print (('3') . '2' . print '4'))
In other words:
1. Concatenate string '3' with string '2' with the return value of `print '4'`, creating the string '321' and outputting '4'
2. Print that string, outputting '321'
3. Print the return value of `print`, which is always 1.
If the `print` operator did have higher precedence than the `and` operator, then you'd expect the third one to print '12' not '21', and indeed that's what I get with php 5.3.6.
`echo` seems to have the lowest precedence, lower even than the `and` operator, as demonstrated by the first line. What's odd is that `print` returns 1 whereas `echo` does not return anything. In fact it seems impossible to use the return value of `echo` in an expression:
echo print "foo"; // foo1
print echo "foo"; // PHP Parse error: syntax error, unexpected T_ECHO in Command line code on line 1
The PHP manual is nice enough to have an [operator precedence table](http://us3.php.net/manual/en/language.operators.precedence.php) but it conveniently does not list any of this.
<|eor|><|eoss|><|endoftext|>
| 8 |
lolphp
|
ealf
|
j7z1z
|
<|sols|><|sot|>GTO: $a = new stdclass(); unset($a->foo->bar->baz); var_dump($a);<|eot|><|sol|>http://codepad.org/ICTy0w3O<|eol|><|eols|><|endoftext|>
| 12 |
lolphp
|
ch0wn
|
fz980
|
<|sols|><|sot|>NoSQL Request Injection Attacks thanks to Magic Variables<|eot|><|sol|>http://www.php.net/manual/en/mongo.security.php<|eol|><|eols|><|endoftext|>
| 11 |
lolphp
|
ealf
|
eldv2
|
<|soss|><|sot|>exit -1;<|eot|><|sost|><|eost|><|eoss|><|endoftext|>
| 10 |
lolphp
|
Takeoded
|
hj7gbq
|
<|sols|><|sot|>display_errors=1 for "HTTP 200 OK", display_errors=0 for "HTTP 500 Internal Server Error" ...<|eot|><|sol|>https://3v4l.org/LElPO<|eol|><|eols|><|endoftext|>
| 8 |
lolphp
|
Takeoded
|
fwl7z06
|
<|sols|><|sot|>display_errors=1 for "HTTP 200 OK", display_errors=0 for "HTTP 500 Internal Server Error" ...<|eot|><|sol|>https://3v4l.org/LElPO<|eol|><|sor|>You forgot the closing php tag<|eor|><|soopr|>quoting section 2.2 of [PSR12](https://www.php-fig.org/psr/psr-12/):
```
The closing ?> tag MUST be omitted from files containing only PHP.
```
but as a rule of thumb, you should only use closing tags when you absolutely have to. if you use closing tags where you don't need it, if you accidentally get a newline or space after the closing tag, the space will be printed to the browser, and that will break header() calls in other code, your code will be more prone to the
> Warning: Cannot modify header information - headers already sent by (output started at /some/file.php:12) in /some/file.php on line 23
- error when you use closing tags..
TL;DR: rule of thumb: don't use closing tags.<|eoopr|><|eols|><|endoftext|>
| 6 |
lolphp
|
Jinxuan
|
ej5k29
|
<|soss|><|sot|>array_diff, array_udiff, array_diff_assoc, array_udiff_assoc, array_diff_keys, array_undiff_keys and +<|eot|><|sost|>Therefore is a lot of array\_diff function names in php by respecting key differently.
Meanwhile, it does not provide array\_merge\_assoc to always respect key associatively. If you want to respect key associatively when merging, you need to use `+`<|eost|><|eoss|><|endoftext|>
| 10 |
lolphp
|
Altreus
|
fcxibz8
|
<|soss|><|sot|>array_diff, array_udiff, array_diff_assoc, array_udiff_assoc, array_diff_keys, array_undiff_keys and +<|eot|><|sost|>Therefore is a lot of array\_diff function names in php by respecting key differently.
Meanwhile, it does not provide array\_merge\_assoc to always respect key associatively. If you want to respect key associatively when merging, you need to use `+`<|eost|><|sor|>Of all the stupid in PHP, conflating the concepts of list and dictionary is up there with the worst. A considerable amount of its functionality is making up for this problem! And they won't fix it!
Tableflip emoji
Edit: thanks for the splendid award!<|eor|><|eoss|><|endoftext|>
| 10 |
lolphp
|
Takeoded
|
dy2vh0
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|eols|><|endoftext|>
| 8 |
lolphp
|
barubary
|
f7z2r9n
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|sor|>You know what the docs mean, and everyone who reads it would.<|eor|><|sor|>I don't. What is the `string $encoding = mb_internal_encoding()` part supposed to mean?<|eor|><|sor|>It means that this function can be used to either set or get the current encoding.
So you could write
$encoding = mb_internal_encoding();
or
mb_internal_encoding("UTF-8");
The `string $encoding` part means that the argument to this function must be a string. If you don't provide an argument, the default behavior is to not change the encoding.
This is legal, but does nothing:
mb_internal_encoding();<|eor|><|sor|>But that doesn't make sense. The result of `mb_internal_encoding()` is very different from `mb_internal_encoding(mb_internal_encoding())`: The former returns a string; the latter returns a boolean.
Why not do something like [`mb_language`](https://www.php.net/manual/en/function.mb-language.php)? This page documents the setter/getter aspects separately:
> mb_language ( string $language ) : bool
> mb_language ( void ) : string
... which neatly shows what's actually going on, provides accurate return types (instead of just `mixed`), and doesn't involve bogus default arguments.<|eor|><|eols|><|endoftext|>
| 17 |
lolphp
|
shaql
|
f81wkwm
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|sor|>Are you sure about that? Docs says function returns current encoding if argument is not passed. Recursive function call looks like an error in docs.<|eor|><|soopr|>>Recursive function call looks like an error in docs.
yup, it doesn't actually work that way, but the docs make it look like it.
[https://i.imgur.com/BSwpoMA.png](https://i.imgur.com/BSwpoMA.png)<|eoopr|><|sor|>> yup, it doesn't actually work that way
So why are we laughing at PHP if it doesn't actually do that?<|eor|><|sor|>We're laughing at PHP docs.<|eor|><|eols|><|endoftext|>
| 12 |
lolphp
|
barubary
|
f7yw9ns
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|sor|>You know what the docs mean, and everyone who reads it would.<|eor|><|sor|>I don't. What is the `string $encoding = mb_internal_encoding()` part supposed to mean?<|eor|><|eols|><|endoftext|>
| 11 |
lolphp
|
Takeoded
|
f7yp3c4
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|soopr|>if it's called without any arguments, then.. it will call itself, without any arguments -- signed, docs<|eoopr|><|sor|>Not true.<|eor|><|soopr|>[https://i.imgur.com/BSwpoMA.png](https://i.imgur.com/BSwpoMA.png)<|eoopr|><|eols|><|endoftext|>
| 11 |
lolphp
|
barubary
|
f7yvc5k
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|soopr|>if it's called without any arguments, then.. it will call itself, without any arguments -- signed, docs<|eoopr|><|sor|>Not true.<|eor|><|sor|>That's the whole point: The docs aren't telling the truth.<|eor|><|eols|><|endoftext|>
| 11 |
lolphp
|
zushk
|
f7y3haz
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|sor|>Are you sure about that? Docs says function returns current encoding if argument is not passed. Recursive function call looks like an error in docs.<|eor|><|eols|><|endoftext|>
| 9 |
lolphp
|
barubary
|
f7yu80k
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|sor|>Nice find.
Not much better: [`mb_chr`](https://www.php.net/manual/en/function.mb-chr.php)
> **Warning** This function is currently not documented; only its argument list is available.
Has been undocumented since 2017, I believe.<|eor|><|eols|><|endoftext|>
| 9 |
lolphp
|
Takeoded
|
f7ypet0
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|sor|>Are you sure about that? Docs says function returns current encoding if argument is not passed. Recursive function call looks like an error in docs.<|eor|><|soopr|>>Recursive function call looks like an error in docs.
yup, it doesn't actually work that way, but the docs make it look like it.
[https://i.imgur.com/BSwpoMA.png](https://i.imgur.com/BSwpoMA.png)<|eoopr|><|eols|><|endoftext|>
| 9 |
lolphp
|
Takeoded
|
f7xzt0c
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|soopr|>if it's called without any arguments, then.. it will call itself, without any arguments -- signed, docs<|eoopr|><|eols|><|endoftext|>
| 8 |
lolphp
|
Takeoded
|
f8461ow
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|sor|>You know what the docs mean, and everyone who reads it would.<|eor|><|soopr|> yeah but it still looks funny, or at least I thought it was funny<|eoopr|><|sor|>Without evaluating the humor of the situation; it doesnt fit in r/lolphp.<|eor|><|soopr|>let me get this straight,
> php documentation lols does not fit in /r/lolphp
is that correct?<|eoopr|><|eols|><|endoftext|>
| 7 |
lolphp
|
the_alias_of_andrea
|
f7yvr1i
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|sor|>You know what the docs mean, and everyone who reads it would.<|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
Cranio76
|
f7y5rnf
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|soopr|>if it's called without any arguments, then.. it will call itself, without any arguments -- signed, docs<|eoopr|><|sor|>Not true.<|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
Crandom
|
f8163z2
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|soopr|>if it's called without any arguments, then.. it will call itself, without any arguments -- signed, docs<|eoopr|><|sor|>Not true.<|eor|><|soopr|>[https://i.imgur.com/BSwpoMA.png](https://i.imgur.com/BSwpoMA.png)<|eoopr|><|sor|>I don't believe anything in the php docs without a test<|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
Takeoded
|
f7z6p55
|
<|sols|><|sot|>mb_internal_encoding()'s default behavior is.. a stack overflow<|eot|><|sol|>https://www.php.net/manual/en/function.mb-internal-encoding.php<|eol|><|sor|>You know what the docs mean, and everyone who reads it would.<|eor|><|sor|>I don't. What is the `string $encoding = mb_internal_encoding()` part supposed to mean?<|eor|><|sor|>It means that this function can be used to either set or get the current encoding.
So you could write
$encoding = mb_internal_encoding();
or
mb_internal_encoding("UTF-8");
The `string $encoding` part means that the argument to this function must be a string. If you don't provide an argument, the default behavior is to not change the encoding.
This is legal, but does nothing:
mb_internal_encoding();<|eor|><|sor|>But that doesn't make sense. The result of `mb_internal_encoding()` is very different from `mb_internal_encoding(mb_internal_encoding())`: The former returns a string; the latter returns a boolean.
Why not do something like [`mb_language`](https://www.php.net/manual/en/function.mb-language.php)? This page documents the setter/getter aspects separately:
> mb_language ( string $language ) : bool
> mb_language ( void ) : string
... which neatly shows what's actually going on, provides accurate return types (instead of just `mixed`), and doesn't involve bogus default arguments.<|eor|><|soopr|>that's a great idea actually, someone should do that on the mb\_internal\_encoding() page!<|eoopr|><|eols|><|endoftext|>
| 5 |
lolphp
|
Takeoded
|
czos0d
|
<|sols|><|sot|>explode()'s limit doesn't work with 0.<|eot|><|sol|>https://3v4l.org/5TjXl<|eol|><|eols|><|endoftext|>
| 7 |
lolphp
|
maweki
|
eyztq3j
|
<|sols|><|sot|>explode()'s limit doesn't work with 0.<|eot|><|sol|>https://3v4l.org/5TjXl<|eol|><|sor|>At least the documentation (https://www.php.net/manual/en/function.explode.php) says as much:
> If the limit parameter is zero, then this is treated as 1.
Can we instead talk about "If delimiter is an empty string (""), explode() will return FALSE.". With python having an exception and JS splitting at UTF-16 codepoints this seems like the worst of all worlds.<|eor|><|eols|><|endoftext|>
| 24 |
lolphp
|
SirClueless
|
eyzowoq
|
<|sols|><|sot|>explode()'s limit doesn't work with 0.<|eot|><|sol|>https://3v4l.org/5TjXl<|eol|><|sor|>You're trying to divide a string into 0 elements? Good luck with that.<|eor|><|eols|><|endoftext|>
| 17 |
lolphp
|
SirClueless
|
eyzpo54
|
<|sols|><|sot|>explode()'s limit doesn't work with 0.<|eot|><|sol|>https://3v4l.org/5TjXl<|eol|><|sor|>You're trying to divide a string into 0 elements? Good luck with that.<|eor|><|soopr|>try doing it in javascript then:
"hello SirClueless, How are you doing?".split(" ",0);
this tells javascript to split the string into an array at every space in the string, but to not return more than 0 elements, what do you think happens? (php's explode() is the same as javascript's split()), try it!
[https://i.imgur.com/J09l52H.png](https://i.imgur.com/J09l52H.png)<|eoopr|><|sor|>Javascript's `split()` is not the same function. `explode()` returns the remainder of the string in the last value when it runs into a delimiter limit, `split()` does not. So they function differently in the pathological 0 case.<|eor|><|eols|><|endoftext|>
| 14 |
lolphp
|
SirClueless
|
eyztn6a
|
<|sols|><|sot|>explode()'s limit doesn't work with 0.<|eot|><|sol|>https://3v4l.org/5TjXl<|eol|><|sor|>You're trying to divide a string into 0 elements? Good luck with that.<|eor|><|soopr|>try doing it in javascript then:
"hello SirClueless, How are you doing?".split(" ",0);
this tells javascript to split the string into an array at every space in the string, but to not return more than 0 elements, what do you think happens? (php's explode() is the same as javascript's split()), try it!
[https://i.imgur.com/J09l52H.png](https://i.imgur.com/J09l52H.png)<|eoopr|><|sor|>Javascript's `split()` is not the same function. `explode()` returns the remainder of the string in the last value when it runs into a delimiter limit, `split()` does not. So they function differently in the pathological 0 case.<|eor|><|soopr|>good point, they're not exactly the same, split does not append the remaining data to the last element, explode does. but that php creates an element where 0 elements are allowed, that still sounds like a bug to me.<|eoopr|><|sor|>PHP documents pretty clearly that [0 is treated the same as 1](https://www.php.net/manual/en/function.explode.php).
It looks a bit silly here because it's just the empty string, it makes more sense if you try `explode(" ","hello",0)` or something. Part of the design of `explode()` is that it never deletes any string data. So that `implode()` can always restore the original string. If `explode()` ever could return zero string pieces this would be impossible, so they code it never to do so and document it as such.
https://3v4l.org/l4XB6<|eor|><|eols|><|endoftext|>
| 6 |
lolphp
|
godman_8
|
776wyr
|
<|soss|><|sot|>Inconsistent print?<|eot|><|sost|>// Run these two sections of code separately for this to work.
// This outputs the date string
////////////////////////////////////////////
<?php
$today = new DateTime();
print_r($today);
print($today->date);
////////////////////////////////////////////
// This throws an error
<?php
$today = new DateTime();
print($today->date);
////////////////////////////////////////////
I've tried this on php 7.1.8 and 7.1.10 locally
Also here's another test
https://3v4l.org/r8VqE
according to some in #php, the first example should not work, but it still outputs a string (when it should not.)
<|eost|><|eoss|><|endoftext|>
| 9 |
lolphp
|
squiggleslash
|
dojiapy
|
<|soss|><|sot|>Inconsistent print?<|eot|><|sost|>// Run these two sections of code separately for this to work.
// This outputs the date string
////////////////////////////////////////////
<?php
$today = new DateTime();
print_r($today);
print($today->date);
////////////////////////////////////////////
// This throws an error
<?php
$today = new DateTime();
print($today->date);
////////////////////////////////////////////
I've tried this on php 7.1.8 and 7.1.10 locally
Also here's another test
https://3v4l.org/r8VqE
according to some in #php, the first example should not work, but it still outputs a string (when it should not.)
<|eost|><|sor|>[deleted]<|eor|><|soopr|>explain please?<|eoopr|><|sor|>It's a word generally used as part of a request to show respect for the person of whom the request is being made, but that's not important right now.
<|eor|><|eoss|><|endoftext|>
| 14 |
lolphp
|
godman_8
|
dojiwo6
|
<|soss|><|sot|>Inconsistent print?<|eot|><|sost|>// Run these two sections of code separately for this to work.
// This outputs the date string
////////////////////////////////////////////
<?php
$today = new DateTime();
print_r($today);
print($today->date);
////////////////////////////////////////////
// This throws an error
<?php
$today = new DateTime();
print($today->date);
////////////////////////////////////////////
I've tried this on php 7.1.8 and 7.1.10 locally
Also here's another test
https://3v4l.org/r8VqE
according to some in #php, the first example should not work, but it still outputs a string (when it should not.)
<|eost|><|sor|>You're not supposed to access the properties of DateTime objects directly. You should be using the methods. The properties are undocumented in the manual as far as I can see.
This [PHP issue](https://bugs.php.net/bug.php?id=49382) indicates the properties only exist so that print_r and var_dump give some useful output<|eor|><|soopr|>alright, so it's bug and has been reopened as another bug report.
seems simple to fix and it has been ~8 years lol
thank you for your reply<|eoopr|><|eoss|><|endoftext|>
| 9 |
lolphp
|
MonkeeSage
|
dokt46r
|
<|soss|><|sot|>Inconsistent print?<|eot|><|sost|>// Run these two sections of code separately for this to work.
// This outputs the date string
////////////////////////////////////////////
<?php
$today = new DateTime();
print_r($today);
print($today->date);
////////////////////////////////////////////
// This throws an error
<?php
$today = new DateTime();
print($today->date);
////////////////////////////////////////////
I've tried this on php 7.1.8 and 7.1.10 locally
Also here's another test
https://3v4l.org/r8VqE
according to some in #php, the first example should not work, but it still outputs a string (when it should not.)
<|eost|><|sor|>You're not supposed to access the properties of DateTime objects directly. You should be using the methods. The properties are undocumented in the manual as far as I can see.
This [PHP issue](https://bugs.php.net/bug.php?id=49382) indicates the properties only exist so that print_r and var_dump give some useful output<|eor|><|soopr|>alright, so it's bug and has been reopened as another bug report.
seems simple to fix and it has been ~8 years lol
thank you for your reply<|eoopr|><|sor|>> seems simple to fix and it has been ~8 years lol
PHP devs: "[Hold my beer](https://bugs.php.net/search.php?limit=30&order_by=id&direction=ASC&cmd=display&status=Open&bug_type=All)"
<|eor|><|eoss|><|endoftext|>
| 9 |
lolphp
|
hfern
|
2uj8pu
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|eols|><|endoftext|>
| 9 |
lolphp
|
cfreak2399
|
co8wqz9
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>The spaceship operator is a thing in Perl<|eor|><|eols|><|endoftext|>
| 18 |
lolphp
|
Porges
|
co9o41k
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>It's a shame this is type-juggled like `==`. A new comparison operator especially a single unified `<=>` would have been a prime opportunity to fix what's broken about `<`/`==`/`>`.
(Such an operator could actually be transitive: given that `$a < $b` and `$b < $c`, one could conclude that `$a < $c`!)
Among other behaviors, PHP's type-juggled operators compare strings numerically if both string operands look like numbers. This well, this causes problems, so PHP added `===` which avoids reinterpreting its operands and tests them for equality them as-is. However, there's no similar operator for comparisons, leading to intransitive comparisons **even for values of the same type**, which causes things like [array sorting that depends on the order of elements and the order of comparisons inside `sort()`](http://3v4l.org/TMEbq).
A single new comparison operator like `<=>` would be ideal for adding non-type-juggled comparisons, since as the RFC points out, less than, less than or equal, equality, greater than or equal, and greater than can all be implemented in terms of `<=>`. It seems to me that this is a missed opportunity but then again, that's exactly what I would expect.<|eor|><|sor|>Don't worry, `<==>` will come later.<|eor|><|eols|><|endoftext|>
| 18 |
lolphp
|
Neckbeard_Prime
|
co9udi8
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>It's a shame this is type-juggled like `==`. A new comparison operator especially a single unified `<=>` would have been a prime opportunity to fix what's broken about `<`/`==`/`>`.
(Such an operator could actually be transitive: given that `$a < $b` and `$b < $c`, one could conclude that `$a < $c`!)
Among other behaviors, PHP's type-juggled operators compare strings numerically if both string operands look like numbers. This well, this causes problems, so PHP added `===` which avoids reinterpreting its operands and tests them for equality them as-is. However, there's no similar operator for comparisons, leading to intransitive comparisons **even for values of the same type**, which causes things like [array sorting that depends on the order of elements and the order of comparisons inside `sort()`](http://3v4l.org/TMEbq).
A single new comparison operator like `<=>` would be ideal for adding non-type-juggled comparisons, since as the RFC points out, less than, less than or equal, equality, greater than or equal, and greater than can all be implemented in terms of `<=>`. It seems to me that this is a missed opportunity but then again, that's exactly what I would expect.<|eor|><|sor|>Don't worry, `<==>` will come later.<|eor|><|sor|>And then real_<==><|eor|><|eols|><|endoftext|>
| 17 |
lolphp
|
willglynn
|
co91j5t
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>It's a shame this is type-juggled like `==`. A new comparison operator especially a single unified `<=>` would have been a prime opportunity to fix what's broken about `<`/`==`/`>`.
(Such an operator could actually be transitive: given that `$a < $b` and `$b < $c`, one could conclude that `$a < $c`!)
Among other behaviors, PHP's type-juggled operators compare strings numerically if both string operands look like numbers. This well, this causes problems, so PHP added `===` which avoids reinterpreting its operands and tests them for equality them as-is. However, there's no similar operator for comparisons, leading to intransitive comparisons **even for values of the same type**, which causes things like [array sorting that depends on the order of elements and the order of comparisons inside `sort()`](http://3v4l.org/TMEbq).
A single new comparison operator like `<=>` would be ideal for adding non-type-juggled comparisons, since as the RFC points out, less than, less than or equal, equality, greater than or equal, and greater than can all be implemented in terms of `<=>`. It seems to me that this is a missed opportunity but then again, that's exactly what I would expect.<|eor|><|eols|><|endoftext|>
| 14 |
lolphp
|
djsumdog
|
cob6z2n
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>When are we getting the ()====> operator?<|eor|><|sor|>()===D~ if you want to be type-safe<|eor|><|eols|><|endoftext|>
| 12 |
lolphp
|
mesoscalevortex
|
co9vhz9
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>When are we getting the ()====> operator?<|eor|><|eols|><|endoftext|>
| 9 |
lolphp
|
tdammers
|
co8x9tl
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>Or how about making a language where people can implement their own operators, just like that; then people can provide this stuff as libraries, instead of adding more and more bloat to the core language...<|eor|><|eols|><|endoftext|>
| 9 |
lolphp
|
allthediamonds
|
cob47wo
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>`T_SPACESHIP`? Really?
Other than that, it's cool for them to try and chase feature parity with Perl 4.<|eor|><|eols|><|endoftext|>
| 7 |
lolphp
|
thelordofcheese
|
co93rju
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|soopr|>Doesn't compare($a, $b) seem more appropriate then introducing a language operator?
Edit: removed sarcasm :/<|eoopr|><|sor|>Yeah, simplified aliases are stupid. That's why I code everything in ASM.<|eor|><|eols|><|endoftext|>
| 6 |
lolphp
|
duskwuff
|
co9dejl
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>But.. but... why the hell would you do -1 if the righthand expression is greater? That makes no sense at all!<|eor|><|sor|>For consistency with functions like [`strcmp()`](http://php.net/manual/en/function.strcmp.php), and so that it can be used sensibly in a sort callback.<|eor|><|eols|><|endoftext|>
| 6 |
lolphp
|
Various_Pickles
|
cob6doh
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>It's a shame this is type-juggled like `==`. A new comparison operator especially a single unified `<=>` would have been a prime opportunity to fix what's broken about `<`/`==`/`>`.
(Such an operator could actually be transitive: given that `$a < $b` and `$b < $c`, one could conclude that `$a < $c`!)
Among other behaviors, PHP's type-juggled operators compare strings numerically if both string operands look like numbers. This well, this causes problems, so PHP added `===` which avoids reinterpreting its operands and tests them for equality them as-is. However, there's no similar operator for comparisons, leading to intransitive comparisons **even for values of the same type**, which causes things like [array sorting that depends on the order of elements and the order of comparisons inside `sort()`](http://3v4l.org/TMEbq).
A single new comparison operator like `<=>` would be ideal for adding non-type-juggled comparisons, since as the RFC points out, less than, less than or equal, equality, greater than or equal, and greater than can all be implemented in terms of `<=>`. It seems to me that this is a missed opportunity but then again, that's exactly what I would expect.<|eor|><|sor|>Don't worry, `<==>` will come later.<|eor|><|sor|>And then real_<==><|eor|><|sor|>"11foo" == 11 for life!<|eor|><|eols|><|endoftext|>
| 6 |
lolphp
|
vytah
|
coej47j
|
<|sols|><|sot|>Library function turns language operator: The <=> Spaceship Operator<|eot|><|sol|>https://wiki.php.net/rfc/combined-comparison-operator<|eol|><|sor|>But.. but... why the hell would you do -1 if the righthand expression is greater? That makes no sense at all!<|eor|><|sor|>Use this as a mnemonic:
2 3 = 1
2 <=> 3 = 1
4 4 = 0
4 <=> 4 = 0
7 6 = 1
7 <=> 6 = 1
<|eor|><|eols|><|endoftext|>
| 5 |
lolphp
|
ealf
|
g4yyy
|
<|soss|><|sot|>Which is true, (++$a == $a) or ($a == ++$a)?<|eot|><|sost|><|eost|><|eoss|><|endoftext|>
| 10 |
lolphp
|
bobindashadows
|
c1kzsot
|
<|soss|><|sot|>Which is true, (++$a == $a) or ($a == ++$a)?<|eot|><|sost|><|eost|><|sor|>Both?! What the fuck?!<|eor|><|eoss|><|endoftext|>
| 8 |
lolphp
|
ealf
|
f91wt
|
<|soss|><|sot|>Segfault the interpreter with a typo<|eot|><|sost|> class A {
var $a;
public function __toString() {
return $this>a;
}
}
echo new A();
... outputs ...
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00007fff5f3ffff8
0x00000001002dae57 in vspprintf ()
<|eost|><|eoss|><|endoftext|>
| 11 |
lolphp
|
saintpetejackboy
|
ewxzt5
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|eoss|><|endoftext|>
| 6 |
lolphp
|
nikic
|
fg64gwp
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>Back then, PHP used the rand() implementation provided by libc. On some systems it is/was notoriously bad. Nowadays PHP will always use its own rand() implementation, which does not suffer from small range or bad distribution (though mt19937 is not state of the art, mainly because it has large state and is fairly slow).<|eor|><|eoss|><|endoftext|>
| 42 |
lolphp
|
beerdude26
|
fg5x3jb
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>PHP random has had multiple bugs regarding randomness. Back a few years ago PHP random only returned odd numbers. Its bugs like this that are riddled in the rotten internals of PHP.<|eor|><|sor|>> Back a few years ago PHP random only returned odd numbers
lmao<|eor|><|eoss|><|endoftext|>
| 30 |
lolphp
|
perk11
|
fg5mq09
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>Seems alright to me https://puu.sh/F5OXs/20f0deedcd.png
PHP 7.2.24-0ubuntu0.18.04.2 (cli) (built: Jan 13 2020 18:39:59) ( NTS )
<?php
$w = 2000;
$h = 2000;
$img = imagecreatetruecolor($w, $h);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
for ($i = 0; $i < 10000000; $i++) {
$color = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($img, rand(0, $w), rand(0, $h), $color);
}
imagepng($img);
imagedestroy($img);<|eor|><|soopr|>Indeed, this is a vastly different result than I used to get with fairly similar code.<|eoopr|><|sor|>It was fixed in PHP 7.1 https://wiki.php.net/rfc/rng_fixes<|eor|><|eoss|><|endoftext|>
| 21 |
lolphp
|
simon816
|
fg58kkg
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>Seems alright to me https://puu.sh/F5OXs/20f0deedcd.png
PHP 7.2.24-0ubuntu0.18.04.2 (cli) (built: Jan 13 2020 18:39:59) ( NTS )
<?php
$w = 2000;
$h = 2000;
$img = imagecreatetruecolor($w, $h);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
for ($i = 0; $i < 10000000; $i++) {
$color = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($img, rand(0, $w), rand(0, $h), $color);
}
imagepng($img);
imagedestroy($img);<|eor|><|eoss|><|endoftext|>
| 18 |
lolphp
|
sproingie
|
fg6jb8r
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>PHP random has had multiple bugs regarding randomness. Back a few years ago PHP random only returned odd numbers. Its bugs like this that are riddled in the rotten internals of PHP.<|eor|><|sor|>Everyone knows odd numbers are more random than even ones, duh.<|eor|><|eoss|><|endoftext|>
| 18 |
lolphp
|
postmodest
|
fg6uh9p
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>It should be noted that you cannot allocate more than 255 colors to an image, so after 255 calls, imagecolorallocate will return false. (And on my box, you get the very first color added, which is the background color)
So it's not rand() that's borked, it's OP's ability to read the documentation.<|eor|><|eoss|><|endoftext|>
| 11 |
lolphp
|
gerrywastaken
|
fg629nt
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>Seems alright to me https://puu.sh/F5OXs/20f0deedcd.png
PHP 7.2.24-0ubuntu0.18.04.2 (cli) (built: Jan 13 2020 18:39:59) ( NTS )
<?php
$w = 2000;
$h = 2000;
$img = imagecreatetruecolor($w, $h);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
for ($i = 0; $i < 10000000; $i++) {
$color = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($img, rand(0, $w), rand(0, $h), $color);
}
imagepng($img);
imagedestroy($img);<|eor|><|soopr|>Indeed, this is a vastly different result than I used to get with fairly similar code.<|eoopr|><|sor|>It was fixed in PHP 7.1 https://wiki.php.net/rfc/rng_fixes<|eor|><|sor|>Wow, it took 10 years to get a fix! [https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)<|eor|><|eoss|><|endoftext|>
| 9 |
lolphp
|
MUK99
|
fg676x4
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>Back then, PHP used the rand() implementation provided by libc. On some systems it is/was notoriously bad. Nowadays PHP will always use its own rand() implementation, which does not suffer from small range or bad distribution (though mt19937 is not state of the art, mainly because it has large state and is fairly slow).<|eor|><|sor|>When I see a comment from nikic, i upvote<|eor|><|eoss|><|endoftext|>
| 7 |
lolphp
|
postmodest
|
fg6uw6k
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>Seems alright to me https://puu.sh/F5OXs/20f0deedcd.png
PHP 7.2.24-0ubuntu0.18.04.2 (cli) (built: Jan 13 2020 18:39:59) ( NTS )
<?php
$w = 2000;
$h = 2000;
$img = imagecreatetruecolor($w, $h);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
for ($i = 0; $i < 10000000; $i++) {
$color = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($img, rand(0, $w), rand(0, $h), $color);
}
imagepng($img);
imagedestroy($img);<|eor|><|sor|>For the record, imagecolorallocate can only be called 255 times for an image before it starts returning "FALSE" which gets mapped to "0" when you ask for a color (thus returning the background / first color). So if that's what OP is complaining about, then OP didn't read the docs:
<?php
header("Content-type: image/png");
$stext = "";
$x = 800;
$y = 600;
$im = @imagecreate($x, $y) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 128,128,128);
$stnum = 0;
while ($stnum <= 10000){
$stize = rand(0,5);
$xl = rand(0,800);
$yl = rand(0,600);
$r = mt_rand(0,255);
$g = mt_rand(0,255);
$b = mt_rand(0,255);
$text_color = imagecolorallocate($im, $r,$g,$b);
if ($text_color === false) {
$text_color = imagecolorclosest($im,$r,$g,$b);
error_log("ETOOMANYCOLORS $stnum");
}
imagestring($im, $stize, $xl, $yl, $stext, $text_color);
$stnum += 1;
}
imagepng($im);<|eor|><|eoss|><|endoftext|>
| 7 |
lolphp
|
saintpetejackboy
|
fg58oe1
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>Seems alright to me https://puu.sh/F5OXs/20f0deedcd.png
PHP 7.2.24-0ubuntu0.18.04.2 (cli) (built: Jan 13 2020 18:39:59) ( NTS )
<?php
$w = 2000;
$h = 2000;
$img = imagecreatetruecolor($w, $h);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
for ($i = 0; $i < 10000000; $i++) {
$color = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($img, rand(0, $w), rand(0, $h), $color);
}
imagepng($img);
imagedestroy($img);<|eor|><|soopr|>Indeed, this is a vastly different result than I used to get with fairly similar code.<|eoopr|><|eoss|><|endoftext|>
| 7 |
lolphp
|
cleeder
|
fg5fgam
|
<|soss|><|sot|>PHP does not do random<|eot|><|sost|>I posted a bug report many years ago. If it was fixed, nobody seems to recognize it.
My original project was trying to see if there was a pattern in "random noise", so I generated colored dots on the screen, with random colors and x,y coordinates. After many generations, the values became "stuck".
According to other people, this is because I do not understand entropy, this is not a PHP problem, and that supposedly my code was bad (even though I shopped it around to many people and reported the bug, in 2006).
I could test if the bug still exists, but here is my original post:
[https://bugs.php.net/bug.php?id=37409](https://bugs.php.net/bug.php?id=37409)
The response I got on IRC was essentially that it was off-topic, not a problem with PHP, and merely was my inability to comprehend entropy.
Any programmer out here want to generate a ton of randomly positioned, randomly colored dots, on a white background, to determine this? I don't have much time to do it now, but not only does this seem to be an "accepted" bug, but there are also known workarounds and solutions (such as changing the seed sporadically), which means I am not the only one who encountered this and the PHP rand functions did not (or may not) work as expected.<|eost|><|sor|>Seems alright to me https://puu.sh/F5OXs/20f0deedcd.png
PHP 7.2.24-0ubuntu0.18.04.2 (cli) (built: Jan 13 2020 18:39:59) ( NTS )
<?php
$w = 2000;
$h = 2000;
$img = imagecreatetruecolor($w, $h);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
for ($i = 0; $i < 10000000; $i++) {
$color = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($img, rand(0, $w), rand(0, $h), $color);
}
imagepng($img);
imagedestroy($img);<|eor|><|soopr|>Indeed, this is a vastly different result than I used to get with fairly similar code.<|eoopr|><|sor|>Did you test on multiple machines/environments? Was it always 50 iterations, or was it variable? If so, how variable? Did it matter if you ran one instance right after another? What about multiple simultaneously?<|eor|><|eoss|><|endoftext|>
| 7 |
lolphp
|
Mark_Messa
|
docrpk
|
<|soss|><|sot|>PHP setcookies expires<|eot|><|sost|>According to the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#refsect1-function.setcookie-notes) about `setcookie`:
> _Common Pitfalls_:
>
> [...]
>
> If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.
Therefore, I've tried the following PHP code:
<?php
setcookie('foo', '');
print_r(apache_response_headers());
Output:
Array ( [Set-Cookie] => foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0 )
**Question**
- Shouldn't the output be `expires=Mon, 28-Oct-2018 18:10:00 GMT;`?
- Does this means that, instead of setting "expiration time to one year in past", PHP is actually setting expiration time to +1s since Unix epoch?
- If so, does this means that such passage in PHP manual is outdated?
***
**Follow-up**
This behavior changed in 2011:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
> I can only guess its due to batteries on the motherboard being dead.
[GitHub: PHP](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e)
Therefore, since +1s Unix epoch is simpler, cheaper and more robust, now I'm wondering:
- Why "one year in past" in the first place? Any issues with old browsers?
- Why most tutorials over the web keep wrongly teaching `time()-t` in order to delete cookies? Including the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#example-5679):
> **Example #2 setcookie() delete example**
> When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:
<?php
// set the expiration date to one hour ago
setcookie("TestCookie", "", time() - 3600);
setcookie("TestCookie", "", time() - 3600, "/~rasmus/", "example.com", 1);
?><|eost|><|eoss|><|endoftext|>
| 8 |
lolphp
|
Targren
|
f5m7dg2
|
<|soss|><|sot|>PHP setcookies expires<|eot|><|sost|>According to the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#refsect1-function.setcookie-notes) about `setcookie`:
> _Common Pitfalls_:
>
> [...]
>
> If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.
Therefore, I've tried the following PHP code:
<?php
setcookie('foo', '');
print_r(apache_response_headers());
Output:
Array ( [Set-Cookie] => foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0 )
**Question**
- Shouldn't the output be `expires=Mon, 28-Oct-2018 18:10:00 GMT;`?
- Does this means that, instead of setting "expiration time to one year in past", PHP is actually setting expiration time to +1s since Unix epoch?
- If so, does this means that such passage in PHP manual is outdated?
***
**Follow-up**
This behavior changed in 2011:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
> I can only guess its due to batteries on the motherboard being dead.
[GitHub: PHP](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e)
Therefore, since +1s Unix epoch is simpler, cheaper and more robust, now I'm wondering:
- Why "one year in past" in the first place? Any issues with old browsers?
- Why most tutorials over the web keep wrongly teaching `time()-t` in order to delete cookies? Including the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#example-5679):
> **Example #2 setcookie() delete example**
> When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:
<?php
// set the expiration date to one hour ago
setcookie("TestCookie", "", time() - 3600);
setcookie("TestCookie", "", time() - 3600, "/~rasmus/", "example.com", 1);
?><|eost|><|sor|>Manual is probably just out of date. Nothing new there.
Calculating "one year in the past" is silly. Setting it to time()=1 accomplishes the same thing but cheaper.<|eor|><|eoss|><|endoftext|>
| 13 |
lolphp
|
duskwuff
|
f5mk4i9
|
<|soss|><|sot|>PHP setcookies expires<|eot|><|sost|>According to the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#refsect1-function.setcookie-notes) about `setcookie`:
> _Common Pitfalls_:
>
> [...]
>
> If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.
Therefore, I've tried the following PHP code:
<?php
setcookie('foo', '');
print_r(apache_response_headers());
Output:
Array ( [Set-Cookie] => foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0 )
**Question**
- Shouldn't the output be `expires=Mon, 28-Oct-2018 18:10:00 GMT;`?
- Does this means that, instead of setting "expiration time to one year in past", PHP is actually setting expiration time to +1s since Unix epoch?
- If so, does this means that such passage in PHP manual is outdated?
***
**Follow-up**
This behavior changed in 2011:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
> I can only guess its due to batteries on the motherboard being dead.
[GitHub: PHP](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e)
Therefore, since +1s Unix epoch is simpler, cheaper and more robust, now I'm wondering:
- Why "one year in past" in the first place? Any issues with old browsers?
- Why most tutorials over the web keep wrongly teaching `time()-t` in order to delete cookies? Including the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#example-5679):
> **Example #2 setcookie() delete example**
> When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:
<?php
// set the expiration date to one hour ago
setcookie("TestCookie", "", time() - 3600);
setcookie("TestCookie", "", time() - 3600, "/~rasmus/", "example.com", 1);
?><|eost|><|sor|>A very PHPesque solution.<|eor|><|sor|>What is, using a date in the past to clear a cookie? That's an industry standard technique. There isn't any other way of doing it.<|eor|><|eoss|><|endoftext|>
| 12 |
lolphp
|
duskwuff
|
f5mbal2
|
<|soss|><|sot|>PHP setcookies expires<|eot|><|sost|>According to the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#refsect1-function.setcookie-notes) about `setcookie`:
> _Common Pitfalls_:
>
> [...]
>
> If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.
Therefore, I've tried the following PHP code:
<?php
setcookie('foo', '');
print_r(apache_response_headers());
Output:
Array ( [Set-Cookie] => foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0 )
**Question**
- Shouldn't the output be `expires=Mon, 28-Oct-2018 18:10:00 GMT;`?
- Does this means that, instead of setting "expiration time to one year in past", PHP is actually setting expiration time to +1s since Unix epoch?
- If so, does this means that such passage in PHP manual is outdated?
***
**Follow-up**
This behavior changed in 2011:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
> I can only guess its due to batteries on the motherboard being dead.
[GitHub: PHP](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e)
Therefore, since +1s Unix epoch is simpler, cheaper and more robust, now I'm wondering:
- Why "one year in past" in the first place? Any issues with old browsers?
- Why most tutorials over the web keep wrongly teaching `time()-t` in order to delete cookies? Including the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#example-5679):
> **Example #2 setcookie() delete example**
> When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:
<?php
// set the expiration date to one hour ago
setcookie("TestCookie", "", time() - 3600);
setcookie("TestCookie", "", time() - 3600, "/~rasmus/", "example.com", 1);
?><|eost|><|sor|>The documentation is outdated. [This behavior was changed in 2011](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e) because:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
>
> I can only guess its due to batteries on the motherboard being dead.<|eor|><|eoss|><|endoftext|>
| 7 |
lolphp
|
duskwuff
|
f5mbypj
|
<|soss|><|sot|>PHP setcookies expires<|eot|><|sost|>According to the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#refsect1-function.setcookie-notes) about `setcookie`:
> _Common Pitfalls_:
>
> [...]
>
> If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.
Therefore, I've tried the following PHP code:
<?php
setcookie('foo', '');
print_r(apache_response_headers());
Output:
Array ( [Set-Cookie] => foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0 )
**Question**
- Shouldn't the output be `expires=Mon, 28-Oct-2018 18:10:00 GMT;`?
- Does this means that, instead of setting "expiration time to one year in past", PHP is actually setting expiration time to +1s since Unix epoch?
- If so, does this means that such passage in PHP manual is outdated?
***
**Follow-up**
This behavior changed in 2011:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
> I can only guess its due to batteries on the motherboard being dead.
[GitHub: PHP](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e)
Therefore, since +1s Unix epoch is simpler, cheaper and more robust, now I'm wondering:
- Why "one year in past" in the first place? Any issues with old browsers?
- Why most tutorials over the web keep wrongly teaching `time()-t` in order to delete cookies? Including the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#example-5679):
> **Example #2 setcookie() delete example**
> When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:
<?php
// set the expiration date to one hour ago
setcookie("TestCookie", "", time() - 3600);
setcookie("TestCookie", "", time() - 3600, "/~rasmus/", "example.com", 1);
?><|eost|><|sor|>Manual is probably just out of date. Nothing new there.
Calculating "one year in the past" is silly. Setting it to time()=1 accomplishes the same thing but cheaper.<|eor|><|sor|>And -- as noted in the commit message I linked -- it means that the cookie will be successfully unset even if the client's clock is wildly wrong.<|eor|><|eoss|><|endoftext|>
| 7 |
lolphp
|
Targren
|
f5mllqb
|
<|soss|><|sot|>PHP setcookies expires<|eot|><|sost|>According to the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#refsect1-function.setcookie-notes) about `setcookie`:
> _Common Pitfalls_:
>
> [...]
>
> If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.
Therefore, I've tried the following PHP code:
<?php
setcookie('foo', '');
print_r(apache_response_headers());
Output:
Array ( [Set-Cookie] => foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0 )
**Question**
- Shouldn't the output be `expires=Mon, 28-Oct-2018 18:10:00 GMT;`?
- Does this means that, instead of setting "expiration time to one year in past", PHP is actually setting expiration time to +1s since Unix epoch?
- If so, does this means that such passage in PHP manual is outdated?
***
**Follow-up**
This behavior changed in 2011:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
> I can only guess its due to batteries on the motherboard being dead.
[GitHub: PHP](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e)
Therefore, since +1s Unix epoch is simpler, cheaper and more robust, now I'm wondering:
- Why "one year in past" in the first place? Any issues with old browsers?
- Why most tutorials over the web keep wrongly teaching `time()-t` in order to delete cookies? Including the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#example-5679):
> **Example #2 setcookie() delete example**
> When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:
<?php
// set the expiration date to one hour ago
setcookie("TestCookie", "", time() - 3600);
setcookie("TestCookie", "", time() - 3600, "/~rasmus/", "example.com", 1);
?><|eost|><|sor|>The documentation is outdated. [This behavior was changed in 2011](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e) because:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
>
> I can only guess its due to batteries on the motherboard being dead.<|eor|><|soopr|>Now I'm wondering, why complicating to "one year in past" in first place?<|eoopr|><|sor|>That's the real lolphp here<|eor|><|eoss|><|endoftext|>
| 7 |
lolphp
|
AyrA_ch
|
f5msbfq
|
<|soss|><|sot|>PHP setcookies expires<|eot|><|sost|>According to the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#refsect1-function.setcookie-notes) about `setcookie`:
> _Common Pitfalls_:
>
> [...]
>
> If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.
Therefore, I've tried the following PHP code:
<?php
setcookie('foo', '');
print_r(apache_response_headers());
Output:
Array ( [Set-Cookie] => foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0 )
**Question**
- Shouldn't the output be `expires=Mon, 28-Oct-2018 18:10:00 GMT;`?
- Does this means that, instead of setting "expiration time to one year in past", PHP is actually setting expiration time to +1s since Unix epoch?
- If so, does this means that such passage in PHP manual is outdated?
***
**Follow-up**
This behavior changed in 2011:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
> I can only guess its due to batteries on the motherboard being dead.
[GitHub: PHP](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e)
Therefore, since +1s Unix epoch is simpler, cheaper and more robust, now I'm wondering:
- Why "one year in past" in the first place? Any issues with old browsers?
- Why most tutorials over the web keep wrongly teaching `time()-t` in order to delete cookies? Including the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#example-5679):
> **Example #2 setcookie() delete example**
> When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:
<?php
// set the expiration date to one hour ago
setcookie("TestCookie", "", time() - 3600);
setcookie("TestCookie", "", time() - 3600, "/~rasmus/", "example.com", 1);
?><|eost|><|sor|>The documentation is outdated. [This behavior was changed in 2011](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e) because:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
>
> I can only guess its due to batteries on the motherboard being dead.<|eor|><|soopr|>Now I'm wondering, why complicating to "one year in past" in first place?<|eoopr|><|sor|>I believe some braindead browsers would not delete the cookie if the date was way too much in the past.<|eor|><|soopr|>Mind to explain why do you believe so?<|eoopr|><|sor|>> Mind to explain why do you believe so?
Because I had trouble handling cookies and cache expiration in the past with old browsers (try to set a cookie with `Expires=0` in IE up to Version 8 or 9 and it will not like it). Might have to do with someone coding in a routine that doesn't deletes the cookie if the date was before the software was released, because you theoretically can't have a cookie you already possess expire before you could have obtained it (remember, deleting and setting cookies are the same HTTP header so it's done by the same parser logic).
The expiration date is a similar thing. Searching for `Mon, 26 Jul 1997 05:00:00 GMT` gives you results for cache expiration even though you never specified it. Everyone is using that date to make stuff expire. It's not even correct, that date is a Saturday.<|eor|><|eoss|><|endoftext|>
| 6 |
lolphp
|
Mark_Messa
|
f5mdmrv
|
<|soss|><|sot|>PHP setcookies expires<|eot|><|sost|>According to the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#refsect1-function.setcookie-notes) about `setcookie`:
> _Common Pitfalls_:
>
> [...]
>
> If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.
Therefore, I've tried the following PHP code:
<?php
setcookie('foo', '');
print_r(apache_response_headers());
Output:
Array ( [Set-Cookie] => foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0 )
**Question**
- Shouldn't the output be `expires=Mon, 28-Oct-2018 18:10:00 GMT;`?
- Does this means that, instead of setting "expiration time to one year in past", PHP is actually setting expiration time to +1s since Unix epoch?
- If so, does this means that such passage in PHP manual is outdated?
***
**Follow-up**
This behavior changed in 2011:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
> I can only guess its due to batteries on the motherboard being dead.
[GitHub: PHP](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e)
Therefore, since +1s Unix epoch is simpler, cheaper and more robust, now I'm wondering:
- Why "one year in past" in the first place? Any issues with old browsers?
- Why most tutorials over the web keep wrongly teaching `time()-t` in order to delete cookies? Including the [PHP manual](https://www.php.net/manual/en/function.setcookie.php#example-5679):
> **Example #2 setcookie() delete example**
> When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:
<?php
// set the expiration date to one hour ago
setcookie("TestCookie", "", time() - 3600);
setcookie("TestCookie", "", time() - 3600, "/~rasmus/", "example.com", 1);
?><|eost|><|sor|>The documentation is outdated. [This behavior was changed in 2011](https://github.com/php/php-src/commit/b966897a0d7412e0ded08e762aacf52000c8287e) because:
> Turns out that more than 1% of users clocks are more than a year out of date, this causes cookies to never get deleted since the date is in the future.
>
> I can only guess its due to batteries on the motherboard being dead.<|eor|><|soopr|>Now I'm wondering, why complicating to "one year in past" in first place?<|eoopr|><|eoss|><|endoftext|>
| 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.