phpmd icon indicating copy to clipboard operation
phpmd copied to clipboard

Unexpected token when using more varaibles in <?= ?> php echo statement

Open pistej opened this issue 3 years ago • 2 comments

  • PHPMD version: 2.12.0
  • PHP Version: 8.0, 8.1
  • Installation type: composer, in docker image
  • Operating System / Distribution & Version: Alpine, ubuntu 20.04

Current Behavior

Unexpected token: ,, line: 6, col: 10, file:: /test.php

Expected Behavior

Analysis should work

Steps To Reproduce:

  • Install PHPMD composer require --dev phpmd/phpmd
  • create test.php file with code example below
  • run php vendor/bin/phpmd test.php ansi naming

Example code

<?php
$var1 = 'foo';
$var2 = 'bar';
?>

<?= $var1,$var2 ?>

Checks before submitting

  • [x] Be sure that there isn't already an issue about this. See: Issues list
  • [x] Be sure that there isn't already a pull request about this. See: Pull requests
  • [x] I have added every step to reproduce the bug.
  • [x] If possible I added relevant code examples.
  • [x] This issue is about 1 bug and nothing more.
  • [x] The issue has a descriptive title. For example: "JSON rendering failed on Windows for filenames with space".

pistej avatar Jul 26 '22 09:07 pistej

Bug confirmed, meanwhile you can use:

<?php echo $var1,$var2; ?>

Or:

<?= $var1.$var2 ?>

kylekatarnls avatar Aug 08 '22 17:08 kylekatarnls

I'm working on a fix, you can try composer require pdepend/pdepend:dev-fix/short-tags-multiple-variables (if you use PHPMD from composer) to preview it and support comas in <?= ?> tags.

kylekatarnls avatar Aug 12 '22 12:08 kylekatarnls