llaville / php-compatinfo

Library that find out the minimum version and the extensions required for a piece of code to run
https://llaville.github.io/php-compatinfo/7.1/
Other
373 stars 20 forks source link

Short array syntax not recognised #221

Closed FlorentPaillot closed 8 years ago

FlorentPaillot commented 8 years ago

I am using PHP 5.6 and php-compat-info 5.0.0.

When running...

$ php56 /usr/bin/php-compat-info analyser:run src/Router.php

...I got the following report:

"Requires PHP 5.3.0 (min), PHP 5.3.0 (all)"

However, Router.php includes short array syntaxes introduced in PHP 5.4.

Is there any reason why php-compat-info doesn't say that the minimum PHP version required should be 5.4.0?

llaville commented 8 years ago

Could you provide code link (if open source project) or a chunk of code that use the code that seems undetected, please ?

FlorentPaillot commented 8 years ago

Here is a bunch of tests.

First, I created one test per use case where the short array syntax is used in my original code.

Second, I compiled this use cases so the code looks like my original code. It is a very simplistic reproduction of the original structure.

1/ FAILED. The report says "Requires PHP 5.0.0 (min), PHP 5.0.0 (all)".

<?php
class FirstTest
{
    private $propertyEmpty = [];

    public function firstMethod()
    {
        return $this->property;
    }
}

2/ FAILED. The report says "Requires PHP 5.0.0 (min), PHP 5.0.0 (all)".

<?php
class SecondTest
{
    private $propertyFull = [
       'one',
       'two',
       'three'
    ];

    public function firstMethod()
    {
        return $this->property;
    }
}

3/ SUCCEEDED. The report says "Requires PHP 5.4.0 (min), PHP 5.4.0 (all)".

<?php
class ThirdTest
{
    public function secondMethod()
    {
        $array = [];

        return $array;
    }
}

4/ SUCCEEDED. Here the report says "Requires PHP 5.4.0 (min), PHP 5.4.0 (all)".

<?php
class FourthTest
{
    public function thirdMethod($string)
    {
        $string = str_replace(['-', '_'], '', $string);

        return $string;
    }
}

In the fifth case below, I compiled the code above in order for it to look like my original script structure.

5/ FAILED. Here the report says "Requires PHP 5.0.0 (min), PHP 5.0.0 (all)".

<?php
class FifthTest
{
    private $propertyEmpty = [];

    private $propertyFull = [
       'one',
       'two',
       'three'
    ];

    public function thirdMethod($string)
    {
        $string = str_replace(['-', '_'], '', $string);

        return $string;
    }

    public function firstMethod()
    {
        return $this->property;
    }
}

6/ SUCCEEDED. Here the report says "Requires PHP 5.4.0 (min), PHP 5.4.0 (all)". Here, I removed the last method and the test passed.

<?php
class SixthTest
{
    private $propertyEmpty = [];

    private $propertyFull = [
       'one',
       'two',
       'three'
    ];

    public function thirdMethod($string)
    {
        $string = str_replace(['-', '_'], '', $string);

        return $string;
    }
}

Here an archive of all tests: tests.zip

Thanks for having a look at it and good luck while debugging.

llaville commented 8 years ago

Thanks for these tests cases. I'll have a look ASAP

llaville commented 8 years ago

Sorry to reply so lately, but I've not yet have time to have a look on this issue until now.

I've tested first two cases that failed for you, and I got succeeded results both on compatinfo 5.0 and 5.1-dev with PHP 5.6.22 (and compatinfo DB 1.5.0).

I'll have a more deepthly view this week-end, to see if I've forgotten something

FlorentPaillot commented 8 years ago

Her is a copy of what I got in the terminal. I checked again the PHP version, phpCompatInfo version and ran all the tests.

Let me know if I can provide more information.

The Linux machine is a pre-configured Synology NAS.

admin@NAS> php56 --version
PHP 5.6.21 (cli) (built: May 13 2016 19:45:40)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
admin@NAS> php56 /usr/bin/phpco --version
phpCompatInfo version 5.0.0 DB built Dec 04 2015 21:00:36 CET
admin@NAS> php56 /usr/bin/phpco analyser:run FirstTest.php

Data Source Analysed

Directories                                          1
Files                                                1

Extensions Analysis

    Extension Matches REF  EXT min/Max PHP min/Max PHP all
    Core              Core             4.0.0
    Total [1]                          4.0.0

Namespaces Analysis

    Namespace Matches REF  EXT min/Max PHP min/Max PHP all
    +global           Core             4.0.0       5.0.0
    Total [1]                          4.0.0       5.0.0

No interface found

No trait found

Classes Analysis

    Class     Matches REF  EXT min/Max PHP min/Max PHP all
    FirstTest         user             4.0.0       5.4.0
    Total [1]                          4.0.0       5.4.0

No function found

No constant found

No condition found

Requires PHP 5.0.0 (min), PHP 5.0.0 (all)
admin@NAS> php56 /usr/bin/phpco analyser:run SecondTest.php

Data Source Analysed

Directories                                          1
Files                                                1

Extensions Analysis

    Extension Matches REF  EXT min/Max PHP min/Max PHP all
    Core              Core             4.0.0
    Total [1]                          4.0.0

Namespaces Analysis

    Namespace Matches REF  EXT min/Max PHP min/Max PHP all
    +global           Core             4.0.0       5.0.0
    Total [1]                          4.0.0       5.0.0

No interface found

No trait found

Classes Analysis

    Class      Matches REF  EXT min/Max PHP min/Max PHP all
    HeigthTest         user             4.0.0       5.4.0
    Total [1]                           4.0.0       5.4.0

No function found

No constant found

No condition found

Requires PHP 5.0.0 (min), PHP 5.0.0 (all)
admin@NAS> php56 /usr/bin/phpco analyser:run ThirdTest.php

Data Source Analysed

Directories                                          1
Files                                                1

Extensions Analysis

    Extension Matches REF  EXT min/Max PHP min/Max PHP all
    Core              Core             4.0.0
    Total [1]                          4.0.0

Namespaces Analysis

    Namespace Matches REF  EXT min/Max PHP min/Max PHP all
    +global           Core             4.0.0       5.4.0
    Total [1]                          4.0.0       5.4.0

No interface found

No trait found

Classes Analysis

    Class     Matches REF  EXT min/Max PHP min/Max PHP all
    ThirdTest         user             4.0.0       5.4.0
    Total [1]                          4.0.0       5.4.0

No function found

No constant found

No condition found

Requires PHP 5.4.0 (min), PHP 5.4.0 (all)
admin@NAS> php56 /usr/bin/phpco analyser:run FourthTest.php

Data Source Analysed

Directories                                          1
Files                                                1

Extensions Analysis

    Extension Matches REF      EXT min/Max PHP min/Max PHP all
    Core              Core                 4.0.0
    standard          standard 4.0.0       4.0.0
    Total [2]                              4.0.0

Namespaces Analysis

    Namespace Matches REF  EXT min/Max PHP min/Max PHP all
    +global           Core             4.0.0       5.4.0
    Total [1]                          4.0.0       5.4.0

No interface found

No trait found

Classes Analysis

    Class      Matches REF  EXT min/Max PHP min/Max PHP all
    FourthTest         user             4.0.0       5.4.0
    Total [1]                           4.0.0       5.4.0

Functions Analysis

    Function    Matches REF      EXT min/Max PHP min/Max
    str_replace 1       standard 4.0.0       4.0.0
    Total [1]                                4.0.0

No constant found

No condition found

Requires PHP 5.4.0 (min), PHP 5.4.0 (all)
admin@NAS> php56 /usr/bin/phpco analyser:run FifthTest.php

Data Source Analysed

Directories                                          1
Files                                                1

Extensions Analysis

    Extension Matches REF      EXT min/Max PHP min/Max PHP all
    Core              Core                 4.0.0
    standard          standard 4.0.0       4.0.0
    Total [2]                              4.0.0

Namespaces Analysis

    Namespace Matches REF  EXT min/Max PHP min/Max PHP all
    +global           Core             4.0.0       5.0.0
    Total [1]                          4.0.0       5.0.0

No interface found

No trait found

Classes Analysis

    Class     Matches REF  EXT min/Max PHP min/Max PHP all
    FifthTest         user             4.0.0       5.4.0
    Total [1]                          4.0.0       5.4.0

Functions Analysis

    Function    Matches REF      EXT min/Max PHP min/Max
    str_replace 1       standard 4.0.0       4.0.0
    Total [1]                                4.0.0

No constant found

No condition found

Requires PHP 5.0.0 (min), PHP 5.0.0 (all)
admin@NAS> php56 /usr/bin/phpco analyser:run SixthTest.php

Data Source Analysed

Directories                                          1
Files                                                1

Extensions Analysis

    Extension Matches REF      EXT min/Max PHP min/Max PHP all
    Core              Core                 4.0.0
    standard          standard 4.0.0       4.0.0
    Total [2]                              4.0.0

Namespaces Analysis

    Namespace Matches REF  EXT min/Max PHP min/Max PHP all
    +global           Core             4.0.0       5.4.0
    Total [1]                          4.0.0       5.4.0

No interface found

No trait found

Classes Analysis

    Class     Matches REF  EXT min/Max PHP min/Max PHP all
    SixthTest         user             4.0.0       5.4.0
    Total [1]                          4.0.0       5.4.0

Functions Analysis

    Function    Matches REF      EXT min/Max PHP min/Max
    str_replace 1       standard 4.0.0       4.0.0
    Total [1]                                4.0.0

No constant found

No condition found

Requires PHP 5.4.0 (min), PHP 5.4.0 (all)
admin@NAS>
llaville commented 8 years ago

Ok it seems that the php-compatinfo 5.0.0 phar distribution reproduces those issues.

If you clone the source code branch 5.0 and update recents dependencies, you will have no issue. It's my case (on my side).

Try this solution, in waiting for a 5.0.1 release with all others issues fixed in 5.1-dev that I should be able to backport to 5.0.x

llaville commented 8 years ago

A tip for all users that used the PHAR version of compatinfo, and want to see what dependencies are included.

Use the --manifest switch, like this : php phpcompatinfo.phar --manifest

FlorentPaillot commented 8 years ago

Thanks for the update.

I cloned the source code and updated the dependencies. I looked at the user guide for a way of using the code as it is to parse scripts, but I only find instructions on how to use the phar version.

Any hint on how I can parse my script without the phar?

llaville commented 8 years ago

Yes, of course. Replace the command php phpcompainfo.phar by php vendor\bin\phpcompatinfo from your recent refresh git clone repo

FlorentPaillot commented 8 years ago

Thanks. It took me a little while to find that bin file because it wasn't in ./vendor/bin but in ./bin.

I parsed all the test files and php-compat-info specified that the minimum required PHP version is 5.4.0 for all of them!

Problem solved.

llaville commented 8 years ago

Nice to hear it ! But as I previously said, I'll backport recent issues fixed in 5.1-dev and build a new stable version 5.0.1 this week. Stay tuned !

llaville commented 8 years ago

FYI compatinfo 5.0.1 has just been released

FlorentPaillot commented 8 years ago

Thanks. I got it.