5

I'm running Ubuntu 16.04, PHP 7.2.29, and Composer 1.10.5. I'm trying to update a composer update but when it starts to update the packages listed eventually gets to packages that have trailing commas in arrays and this starts throwing off syntax errors.

PHP Parse error:  syntax error, unexpected '' => ' (T_ENCAPSED_AND_WHITESPACE) in /var/www/vendor/yiisoft/extensions.php on line 52

I've attempted to correct these errors directly in the packages (vendors directory) and this does allow me to move forward... except that the errors never stop! (Update: I know this isn't recommended, it was only done for testing purposes)

Samples (Update):

These are samples of the vendor files that are throwing off that syntax error. In all of these (and more) the last lines of the array files are pointed out as the cause. If I remove the trailing commas, the error goes on to find the next vendor file that contains trailing commas.

Sample from /vendors/yiisoft/extensions.php

  'creocoder/yii2-nested-sets' => 
  array (
    'name' => 'creocoder/yii2-nested-sets',
    'version' => '0.9.0.0',
    'alias' => 
    array (
      '@creocoder/nestedsets' => $vendorDir . '/creocoder/yii2-nested-sets/src',
    ),
  ),
);

Sample from /vendors/composer/autoload_classmap.php

    'yii\\widgets\\Pjax' => $vendorDir . '/yiisoft/yii2/widgets/Pjax.php',
    'yii\\widgets\\PjaxAsset' => $vendorDir . '/yiisoft/yii2/widgets/PjaxAsset.php',
    'yii\\widgets\\Spaceless' => $vendorDir . '/yiisoft/yii2/widgets/Spaceless.php',
);

Sample from /vendors/composer/autoload_namespaces.php

    'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/lib'),
    'DaveChild\\TextStatistics' => array($vendorDir . '/davechild/textstatistics/src'),
    '' => array($vendorDir . '/mofodojodino/profanity-filter/src'),
);

As I understand it, trailing commas are a fairly common practice that shouldn't cause any issues in PHP.

Can anybody tell me what's going on or where I could look into next?

Additional Details

I'm thinking the packages being installed shouldn't matter since this seems to be a PHP-wide error but just in case this IS for an older version of Craft CMS 3.0.34, running on Yii 2.0.15.1. I'm working to update out of this version but I can't because of these issues. However, the packages throwing off the errors vary... I mean... I edited files of ~6 different vendors before giving up on that silly battle.

Update

After receiving some feedback I found that running the same setup on a cloud server did not have the issue described. Indicating that somehow running this on VirtualBox/Vagrant setup was triggering it.

cballenar
  • 133
  • 6
  • 1
    Does this answer your question? [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – Jens Apr 11 '20 at 22:32
  • 3
    If you're getting a syntax error from a third-party library, you should take that up with the library author. – Barmar Apr 11 '20 at 22:36
  • **Never** edit files in the vendor directory. Trailing commas in arrays were already supported in PHP 4. So what's the exact code in question? – Nico Haase Apr 12 '20 at 18:48
  • @Jens, unfortunately not, while the syntax is referenced in there and makes sense, this does not explain/solve the underlying issue, i.e.: my instance of PHP recognizing trailing commas as an error for some reason. – cballenar Apr 13 '20 at 01:46
  • @Barmar, unfortunately this is not an issue with any of the packages. As far as I can tell this is happening across packages (even with files from composer itself as shown in the samples added. – cballenar Apr 13 '20 at 01:47
  • @NicoHaase, yup, that was only a test to try to identify the issue, as mentioned, it only led to finding more cases which don't make sense (as pointed out, trailing commas have been long supported. I've copied the samples as an update. Thoughts? :/ Thanks everyone for pitching in! – cballenar Apr 13 '20 at 01:48
  • 1
    Probably an issue with the file system, check this out https://github.com/composer/composer/issues/8608 – Ali Ali Apr 19 '20 at 01:14
  • 1
    Do you run on Virtual Machine or real Ubuntu 16.04? – Taron Saribekyan Apr 19 '20 at 18:17
  • ... looks like you have a severely borked PHP installation. did you compile it yourself or did you get a pre-compiled version? – hanshenrik Apr 20 '20 at 00:04
  • 1
    @AliAli thanks for that, I couldn't believe I was the only running into this. I'll start testing same as the author of the post this evening. – cballenar Apr 20 '20 at 17:53
  • 1
    @TaronSaribekyan this is running on a VM, just like AliAli had suggested in the link. I'd had issues with VMs before but this was new. I'll start looking into this and report back. – cballenar Apr 20 '20 at 17:55
  • Is there some cache involved in your code ? – Melvyn Marigny Apr 21 '20 at 15:05
  • First of all understand it that it is not javascript. Each language has its own symentic way to parse the things before executing any statement. So the php has not it. Take care of comma ( , ). Thanks – Krishan Kumar Apr 23 '20 at 03:52
  • 1
    What is the content of `$vendorDir`? And what exactly is row 52 that is mentioned in the error message? Please show the complete file `/vendors/yiisoft/extensions.php` – mixable Apr 24 '20 at 15:25
  • I tried installing `yiisoft/yii2`, `creocoder/yii2-nested-sets`, etc in both a 5.6 and 7.2 environment using composer. They both failed raising the error of missing the same set of vendor dependencies (e.g. `bower-asset/jquery 2.2.*@stable`). [That current Yii vendor build](https://travis-ci.org/github/creocoder/yii2-nested-sets) seems to be failing as well, and I can't find a previous version of this vendor as easily as I would expect (so I gave up). I understand this is a little bit of a tangent. But perhaps it might contribute to the actual resolution. – Jeroen van der Laan Apr 24 '20 at 21:24
  • Thanks @JeroenvanderLaan, definitely was something with VMs or Vagrant. As soon as I installed the same setup on a Cloud environment the whole and update went through smoothly. I'm not sure all the intricacies that go in the backend that would lead to this though. – cballenar Apr 26 '20 at 13:26

1 Answers1

-2

It looks like composer is not using PHP 7.2 (or above). You can test this by running php -v on the command line. To see if you have PHP 7.2 installed you should also be able to do php7.2 at least on a newer version of ubuntu.

Hope it helps

  • 4
    Please add some more explanation to your answer by editing it. Why should PHP 7.2 be needed? If this was a problem of a traling comma (like given in the title), the minimum version supporting this is PHP 4 – Nico Haase Apr 19 '20 at 10:41