Nope, $i is very much defined in that block of code. Its defined in the foreach statement of 4836 line.

This error should have been generated on the line 4850, which surprising to me, it didn't when the order by clause is empty, just checked that case. Anyways fixing this case and re uploading the patch.