[php-52971] Port fix for PHP bug 52971

Ported from the PHP repo