If $entries contains exactly $resultSize elements at this point, the 'search-continue' below will be missing. I may be wrong but I think this can be fixed easily by changing this to count( $entries ) < $resultSize + 1.