Backport for 3.4 branch: Fix for phar:// stream wrapper with no stub

Exactly the same as #4101 and original #4080 to fix #4012
Hopefully, will be in 3.4.1 (since 3.4 is current stable branch).