I think I stumbled across a bug in PHP. However, to be sure, I am asking here first.
$k=0;
echo preg_replace_callback('/./', function($groups) use ($k) {
return $k++;
}, 'xxxxxx');
Script output: 000000
Expected output: 012345
Am I missing something?