utf8_is_valid("\xE2\x82\xAC\xE2\x82") returns TRUE. However, this ends with an incomplete character "\xE2\x82", so should return FALSE.
I believe adding the following after the main for loop, just before the final "return TRUE" should fix this:
if (0 != $mState)
// String ends with an incomplete character