$counter = $counter++ does not work because $variable++ is not just called the "increment operator", but the "
post increment operator". It will only increment the variable once the line of code has run. It is probably just a timing issue with PHP due to the fact that the increment operator is not typically used that way. If you did want to use an increment operator like that, you would need to use the "
pre increment operator", like this:
However, this still suffers from the fact that this is not the intended usage of the operator, and because of that it may have strange effects in PHP. The recommended way to use it is still as a straight unary operation: