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
371 stars 21 forks source link

PHP 7.1 Nullable types not being detected #273

Closed LucasKovacs closed 4 years ago

LucasKovacs commented 4 years ago

PHP 7.1 nullable types are not being detected.

For example, the following block of code won't be identified as a PHP 7.1 block

<?php

function testReturn(): ?string
{
    return 'elePHPant';
}

var_dump(testReturn());

function testReturn(): ?string
{
    return null;
}

var_dump(testReturn());

function test(?string $name)
{
    var_dump($name);
}

test('elePHPant');
test(null);
test();

Currently using: version 5.3.0 DB version 2.16.0 Installed via Composer

Reference: https://www.php.net/manual/en/migration71.new-features.php

llaville commented 4 years ago

Thanks for reporting (with details: I appreciate a lot), but the situation is already known !

To resume, all versions until 5.3.0 are not yet ready to detect all PHP 7 features. This is the main goal of future 5.4.0 that will come soon now.

Branch 5.4 is currently under huge refactoring to avoid monolithic architecture (legacy) code, enhance maintainibility, and allow to add easily fix about detection/feature missing.

I may be available to push to repository in few hours a running v5.4 that you can test !

llaville commented 4 years ago

With test script added by commit e89de39, future 5.4 will give such result :

 bin/phpcompatinfo analyser:run tests/fixtures/gh273.php

Data Source Analysed

Directories                                          1
Files                                                1
Errors                                               0

Extensions Analysis

    Extension Matches REF      EXT min/Max PHP min/Max PHP all
    Core              Core     4.0.0       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
                      user             7.1.0
    Total [1]                          7.1.0

No interface found

No trait found

No class found

Functions Analysis

    Function    Matches REF      EXT min/Max PHP min/Max
    test                user                 7.1.0
    testReturn1         user                 7.1.0
    testReturn2         user                 7.1.0
    var_dump            standard 4.0.0       4.0.0
    Total [4]                                7.1.0

Constants Analysis

    Constant  Matches REF  EXT min/Max PHP min/Max
    null              Core 4.0.0       4.0.0
    Total [1]                          4.0.0

No condition found

Requires PHP 7.1.0 (min), PHP 7.1.0 (all)
llaville commented 4 years ago

@LucasKovacs : beta code is up and running in repo (branch 5.4), if you want to test the preview

LucasKovacs commented 4 years ago

@llaville I will give it a try! thanks :)

I was not aware that 5.3 did not have full support

llaville commented 4 years ago

See also commit 58660ad995ca025b7080598354970bc121380d61 that handle parameters type hinting

llaville commented 4 years ago

Will be release in two weeks with official release 5.4.0