New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check PHP version in stubs classes #145
Conversation
👎 on that, |
@keradus You are right, but if you want to write a wordpress plugin, the wordpress svn pre-commit hook will simply reject your plugin because symfony/polyfill-php70 is included in the vendors 😞 As you said, stubs will be included only on older version of PHP, and only one time, so I think the "cost" of an |
if wordpress has issues how to properly deal with code, it shall be fixed on wordpress level, if you ask me |
Of course, that's the proper way, and I already asked as you can imagine. But I don't think it's only a wordpress issue, or I would not have opened a PR (I already forked polyfill-php70 and used it in my composer file), as linting all file of a directory to check errors is something often done. |
I agree with @keradus, this is working around someone else's issue. |
When relying on autoloading, a class will not be autoloaded if it already exists in the runtime. So the issue is in the infra running |
Thanks for proposing. |
I am also having this issue when pushing to SVN for the WP plugin repo. The same exact issue as @karser What's the workaround here? |
I don't think this is WordPress doing anything improper. It doesn't seem unreasonable to me to expect that all files in a project are valid according to PHP's own built-in linter. |
@nickyoung87 @TimothyBJacobs Note: This is only for |
Thanks @bshaffer! My only problem with this as a solution is now I have to remember to make that change if this package ever gets updated (and the fix is not included). Hopefully that doesn't happen :D |
as an alternative to applying a diff like @bshaffer does, you could also iterate over the files using bash. I'm using this in my github actions when deploying: for filename in *.php; do
[ -e "$filename" ] || continue
sed -i '2s/^/if (PHP_VERSION_ID < 70000) :\n/' "$filename"
sed -i '$s/$/\nendif;/' "$filename"
done but of course you can run this locally too |
I added a test in stubs classes to prevent
php -l
to fail on polyfills (errors likePHP Fatal error: Cannot declare class ArithmeticError, because the name is already in use
)