Fix for php bug #64802

I included a test case as well.