• I’m submitting a plugin that has some optional functionality which requires PHP 5.5.

    The plugin only loads the files that require PHP 5.5 once it’s checked the PHP version, as per the recommendations here: https://make.www.ads-software.com/plugins/2015/06/05/policy-on-php-versions/

    However, it appears that the pre-commit hook in SVN does a syntax check on ALL files to ensure that they run on PHP 5.2, and does not take into account login in the plugin that doesn’t load such files on PHP < 5.5. Therefore, I receive errors as follows when trying to commit to the repository:

    Transmitting file data ………………………svn: E165001: Commit failed (details follow):
    svn: E165001: Commit blocked by pre-commit hook (exit code 1) with output:
    PHP Parse error: syntax error, unexpected ‘$client’ (T_VARIABLE) in – on line 61

    ***********************************
    PHP error in: amberlink/trunk/vendor/aws/Aws/CommandPool.php:
    Errors parsing amberlink/trunk/vendor/aws/Aws/CommandPool.php
    ***********************************

    Any recommendations on how to resolve this issue? And is this the right place to raise the question?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Actually, the pre-commit hook checks for PHP 5.4 syntax, not 5.2. So, whatever you’re doing on line 61 isn’t 5.4 compatible.

    Currently, 72.1% of all WP installs run 5.4 or less. We’d prefer not to have plugin code in our directory that whitescreens the vast majority of WordPress installations immediately after activation.

    You’re welcome to require PHP 5.5. But we require syntax capable of being parsed by 5.4. And we’d recommend that your main file be 5.2 compatible, and that the PHP version check be in that file, which only loads any other non-5.2 compatible files after the version check is complete.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    FWIW, you can also use the v2 branch of the AWS SDK (that’s what I’m guessing you’re using): https://github.com/aws/aws-sdk-php

    https://github.com/aws/aws-sdk-php/blob/master/src/CommandPool.php#L61

    Not sure why that would fail like that. Might be worth asking Amazon.

    Thread Starter jeffreylicht

    (@jeffreylicht)

    I’m completely on board with ensuring that all plugins are compatible with with older versions of PHP. My actual concern is that the advice being given in the most “official” word on the subject is not consistent with the rules that are being enforced by the Subversion validation.

    From https://make.www.ads-software.com/plugins/2015/06/05/policy-on-php-versions/ :

    Sometimes though, you need more complicated checks. Let’s say your plugin uses PHP namespaces. Those are not supported in PHP 5.2, and will cause a syntax error just from having them in the file, before any of your code runs.

    So, your main plugin file needs to not have namespaces and basically only be a shiv to load the rest of the plugin from another file if the requirements are met:

    if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
        add_action( 'admin_notices', create_function( '', "echo '<div class=\"error\"><p>".__('Plugin Name requires PHP 5.3 to function properly. Please upgrade PHP or deactivate Plugin Name.', 'plugin-name') ."</p></div>';" ) );
        return;
    } else {
        include 'rest-of-plugin.php';
    }

    Here, the plugin does not load the files that can cause errors unless the requirements are met.

    The recommendation in that blog post is to conditionally load PHP files containing code which is not syntactically valid in older versions of PHP. The implication is that those files can be included in the plugin, as long as they aren’t loaded when they wouldn’t be valid. However, the Subversion pre-commit hook is validating every file, whether or not there is logic to prevent it from being loaded on older versions of PHP.

    I’ve worked around the immediate problem by using v2 of the AWS library – thanks Ipstenu! – but still think there’s an issue here to be addressed, either by updating the documentation or changing the validation behavior.

    Hi;

    Just wondering if there’s any update on this as I’m hitting the exact same problem. I have a plugin that requires PHP 5.5. It duly checks (In a 5.2 compatible main plugin file) the PHP version, and if the requirements aren’t met shows a message, doesn’t load any other files, and deactivates itself.

    So – it’s not going to break sites, but at the minute I can’t actually publish it due to the pre-commit hook validation.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    I still don’t understand why you would want to publish a plugin that won’t work for 3/4’ths of the userbase.

    Hi;

    A particular plugin isn’t necessarily aimed at the whole of WordPress’ userbase. So the % of users who are likely to use any given plugin and are on PHP < 5.5 isn’t necessarily the same as the % of the total WP userbase.

    Having a plugin that tells you that you’re out of date, might motivate you to upgrade to run it. I’d agree it’s important to do so in a way that doesn’t just whitescreen and makes you think the plugin / WordPress is at fault.

    Think of it as BrowseHappy for PHP ??

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Well, regardless, we’re looking into raising that syntax check limitation, but it’s not something we have direct control over nor is it something that I can just flip-a-switch to change. So, it may take some time.

    Thanks!

    I still don’t understand why you would want to publish a plugin that won’t work for 3/4’ths of the userbase.

    Samuel, often a plugin might include optional code that only works with PHP 5.5+.
    The plugin would still work with older versions of PHP, but would offer the optional functionality to users with PHP 5.5+.

    An example is https://www.ads-software.com/support/topic/svn-commit-fails-because-of-yield-keyword.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Overzealous subversion pre-commit hook syntax check’ is closed to new replies.