Fixes #2869

Ported https://bugs.php.net/bug.php?id=66021.
got it, thx