• I’m trying to upload an updated version of one of my plugins, and the commit fails due to a “syntax error”:

    Commit blocked by pre-commit hook (exit code 1) with output:
    PHP Parse error:  syntax error, unexpected '.', expecting ')' in - on line 10

    The code is generated by Composer, and it works fine in PHP 5.3 and later. I reckon that the error is due to a rule that applies to PHP 5.2 and earlier.

    Affected code

    <?php
    
    // autoload_static.php @generated by Composer
    
    namespace Composer\Autoload;
    
    class ComposerStaticInit9b09a05c4e06ffb39df7e3d597db9ef6
    {
      public static $files = array (
        // This the affected line. The error is probably caused by the
        // fact that in older versions of PHP it was not possible to
        // use concatenation in variable and property declarations
        '1d1b89d124cc9cb8219922c9d5569199' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest.php',
      );
    
      // Other code...
    }

    The plugin is designed to check for PHP 5.3 or later, and it won’t run without it, therefore the syntax is valid. Is there a way to skip this pre-commit hook?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter Diego

    (@daigo75)

    Note
    This topic can be moved to the Hacks sub-forum, if needed. I actually meant to post it there.

    Diego

    Did you find a solution, I’m having the same issue.

    thanks

    > it works fine in PHP 5.3 and later

    Are you sure? https://3v4l.org/tLT0d shows that it throws a parse error below 5.6. See also, https://php.net/manual/en/migration56.new-features.php#migration56.new-features.const-scalar-exprs

    Thread Starter Diego

    (@daigo75)

    I will need to check that. I tested the code on several systems with PHP 5.3 and 5.4, and it never threw an error. Now I’m suspecting that the code is not even invoked.

    Thread Starter Diego

    (@daigo75)

    I think I got it. You’re right, this kind of static concatenation is supported by PHP 5.6 and later, and Composer uses it automatically at runtime when such version is detected. When the PHP version is older, then the class with the static concatenation is not loaded.

    In other words, everything should work fine in any case, the “incompatible” file may not be used. This, however, doesn’t prevent the commit hooks from disliking it.

    I still don’t have a solution for this, unfortunately.

    Thread Starter Diego

    (@daigo75)

    Temporary workaround
    I rolled back Composer to a previous version, so that it doesn’t produce the static autoloader anymore.

    I needed to updated this post, because my previous suggestion weren’t work, don’t know why it seemed though. Anyway, i get around that problem, when i changed the autoload_real.php a little bit and remove the autoload_static.php.

    In autoload_real.php search for:

    $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');

    And replace that code with:

    $useStaticLoader = false;

    That way, the following if-clauses will NOT load the autoload_static.php.

    Afterwards remove the autoload_static.php to not trigger the SVN-problem.

    Doing that let me push to SVN again.

    I opened an issue about that problem in composer’s issue tracker on Github: link. You welcomed to participate. I would like that see the issue will be dealt with soon, one way or the other.

    Thread Starter Diego

    (@daigo75)

    I already opened an issue for the same reason (see #5255).

    Actually, I tend to agree with their reply. The Composer autoloader works fine in PHP from 5.3 onwards, because the static autoloader is not used below 5.6. If anything, it’s the SVN pre-commit hook that is “too picky”.

    I’m having the same issue. The pre-commit is guilty for this. Will it be updated? It doesn’t seem reasonable to force the use of a legacy Composer, does it?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Syntax error while updating SVN repository’ is closed to new replies.