Patch backported from:
https://github.com/php/php-src/pull/13914
https://github.com/php/php-src/commit/0766ac6e357282eafb51cbdc5383345e7487260b