phpmd / phpmd

PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.
https://phpmd.org
BSD 3-Clause "New" or "Revised" License
2.34k stars 347 forks source link

Unexpected token: ?? #519

Closed richardbrinkman closed 5 years ago

richardbrinkman commented 7 years ago

PHP has introduced the ?? operator. Example usage:

$var = $_GET["param"] ?? "default value"

which is roughly equivalent to:

$var = isset($_GET["param"]) ? $_GET["param"] : "default value"

phpmd gives an Unexpected token: ?? error when these new constructs are used.

mdeboer commented 7 years ago

Are you sure you don't have two PHP versions installed? PHPMD could be run with an older version of PHP than your code is written in.

richardbrinkman commented 7 years ago

Yes I'm sure I run only one PHP version (7.0.22).

Sample PHP file (test.php):

<?php
    var_dump($_GET["var"] ?? "default");
?>

Command: phpmd test.php text cleancode

Output:

/tmp/test.php   -   Unexpected token: ??, line: 2, col: 24, file: /tmp/test.php.
mdeboer commented 7 years ago

What OS are you running? If you're on linux/OSX, can you post the output of: env php -v?

phpmd uses the php binary that's in your PATH and the only thing I can think of it's using a different version (pre 7.0).

richardbrinkman commented 7 years ago

OS: lubuntu 16.04.03 (LTS)

env php -v:

PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

phpmd version: 2.3.2-1build1

running php test.php dumps the expected "default", so surely php 7.0.22 knows the ?? operator.

ravage84 commented 7 years ago

What version of Pdepend are you using? If I recall correctly, the newest version of it should fully support PHP 7.0.

richardbrinkman commented 7 years ago

pdepend version 2.2.2-1build1

ravage84 commented 7 years ago

Can you please verify that behavior with Pdepend 2.5.0? It Should have full PHP 7.0 support.

tvbeek commented 5 years ago

@richardbrinkman can you verify this?

kylekatarnls commented 5 years ago

I can't reproduce I use ?? very often with no incompatibility when running PHPMD. I think it has been fixed in PDepend since.

richardbrinkman commented 5 years ago

The error does not appear any more.