Giter Club home page Giter Club logo

php-compatinfo's Introduction

PHP CompatInfo

StandWithUkraine GitHub Discussions

PHP CompatInfo is a library that can find the minimum version and the extensions required for a piece of code to run.

Running on PHP greater or equal than 7.2 for parsing source code in a format PHP 5.2 to PHP 8.3

Versions

Releases Branch PHP Packagist License Documentation
Stable v5.5.x Branch 5.5 Minimum PHP Version) Stable Version 5.5 License 5.5 Documentation 5.5
Stable v6.5.x Branch 6.5 Minimum PHP Version) Stable Version 6.5 License 6.5 Documentation 6.5
Stable v7.0.x Branch 7.0 Minimum PHP Version) Stable Version 7.0 License 7.0 Documentation 7.0
Stable v7.1.x Branch 7.1 Minimum PHP Version) Stable Version 7.1 License 7.1 Documentation 7.1

Documentation

All the documentation is available on website, generated from the docs folder.

Contributors

  • Laurent Laville (Lead Dev)
  • Thanks to Nikita Popov who wrote a marvellous PHP Parser.
  • Thanks also to Remi Collet, a contributor of first hours.
  • Credits to Davey Shafik. He introduced his proposal in 2004, that gave birth of a PEAR package named PHP_CompatInfo.

php-compatinfo's People

Contributors

cmb69 avatar dennisbecker avatar dregad avatar glensc avatar llaville avatar nickolasburr avatar pxlrbt avatar remicollet avatar siwinski avatar szepeviktor avatar vrana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-compatinfo's Issues

Hash without Mhash extension cause test failure

Since PHP 5.3 mhash extension is deprecated by can be emulated by hash extension
In this case, "php -m" reports both hash and mash

In RHEL-6 php 5.3.3 have hash, but don't have mash
So HashTest fails.

Proposal : keep all mhash* functions and constants only ini mhash reference.

What do you think (I wait your feedback before submitting a PR)

unusable report file

When using print, with --full, --recursive and --report-file option, the result file contains the progress information, which make it nearly unusable.

SO_REUSEPORT missing in Sockets Reference

1) PHP_CompatInfo_Reference_SocketsTest::testGetConstantsFromExtension
Defined constant 'SO_REUSEPORT' not known in Reference.
Failed asserting that an array has the key 'SO_REUSEPORT'.

This new constant is present since PHP 5.4.10 but is only defined if present in system library.

I'm currently working on the fix, and will submit a PR soon.

What about an deadly simple usage?

Spending hours to get your tool to work the "composer" way.

The Autoload thing is not working at all... have you ever testet it
using composer? It does have other sub-paths and finally what
about people who do not like to load your on dev only?

Why isn't there a deadly simple script like your PEAR's CLI that can
be used here? This just doesn't work for me at all.

Why not something like that?

php vendor/pear-bartlett.laurent-laville.org/PHP_CompatInfo/cli.php myFolder

No Autoload please, just a script that can be called. Done

PHP 5.4.12 failed tests

There was 1 failure:

 1) PHP_CompatInfo_Reference_MysqliTest::testGetConstantsFromExtension
 Defined constant 'MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS' not known in Reference.
 Failed asserting that an array has the key 'MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS'.

 /dev/shm/BUILD/php-bartlett-PHP-CompatInfo-2.13.0/PHP_CompatInfo-2.13.0/tests/Reference/GenericTest.php:236

Need 102fae2

Also Need remicollet@c4f2ad1

SO_BINDTODEVICE exists in 5.4.18

With 5.4.18

 There was 1 failure:
 1) PHP_CompatInfo_Reference_SocketsTest::testGetConstantsFromReference
 Constant 'SO_BINDTODEVICE', found in Reference (5.5.1,), exists.
 Failed asserting that true is false.
 /builddir/build/BUILD/php-bartlett-PHP-CompatInfo-2.21.0/PHP_CompatInfo-2.21.0/tests/Reference/GenericTest.php:217
 FAILURES!

So this constant exists in php >= 5.4.18 and >= 5.5.1 (so not in 5.5.0)

ambiguous class report

Sample :
namespace foo;
class bar extends \PDO {
}

Report
\PDO 5.3.0 1
bar 5.3.0 1

Shouldn't \PDO report as PDO ?
Shouldn't bar report as foo\bar ?

"private" keyword reports as "Required PHP 4.0.0 (min)"

PHP_CompatInfo 2.26.0 reports the following code as "Required PHP 4.0.0 (min)":

<?php

class Foo
{
    private $bar;

    private static $baz;
}

Private instance and all class (static) methods are reported as "Required PHP 5.0.0 (min)", as expected.

I have not been able to test with CompatInfo 3.1, because with a local composer install I can't execute compatinfo (Windows/Cygwin), due to wrong paths for required files.

Command line iniSet option ignored

Hello,

Using php-compat-info 2.10.0 with php 5.4.9; I'm trying to execute the following:
$ phpci -d memory_limit=512M -d date.timezone=UTC print --report extension --recur tcpdf_5.9.165

And I actually obtain:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in /usr/share/pear/Bartlett/PHP/Reflect.php on line 316

Looks like my "memory_limit" is being ignored (don't know at the moment if the timezone setting is being ignored too, I don't think tcpdf relies on date anywhere).

I'll be happy to provide you any other informations that could help you.

Thank you :)

2.18.0

Add support to final stable version of PHP 5.5

Report "Required PHP 4.0.0 (min)" on short array syntax 2

This is a follow-up of issue #105.

The assignment now work:

// File test.php
<?php
$array = [];
$array = [1];
$array = [1,2];
$array = [1,2,3];
?>

The CLI tool does not report the correct required version (5.4) when encountering the short array syntax.

http://www.php.net/manual/en/migration54.new-features.php

// File test2.php
<?php
function foo($array) {
        return true;
}

foo([]);
foo([1]);
foo([1,2]);
foo([1,2,3]);
?>
$ php ~/PHP_CompatInfo-2.25.0/scripts/phpci print --reference=ALL test.php
PHP_CompatInfo DEV by Laurent Laville

.

-------------------------------------------------------------------------------
PHP COMPAT INFO REPORT SUMMARY
-------------------------------------------------------------------------------
A TOTAL OF
 1 EXTENSION 1 FUNCTION 1 CONSTANT
WERE FOUND IN 1 FILE
REQUIRED PHP 4.0.0 (MIN)
-------------------------------------------------------------------------------


Required PHP 4.0.0 (min)

Alert on wrong version

I develop plugins for wordpress but the minimum requirement is PHP 5.2.4.
I check weekly the minimum version but is possible get an alert that report the wrong line for the minimum requirement?
Now i scan manually in search of anonymous function and other things.

broken extension report

With phpci 2.14.0

$ phpci print --recursive --report extension PropertyAccess-2.2.0/Symfony/Component/PropertyAccess/
PHP_CompatInfo 2.14.0 by Laurent Laville

...........................

Notice: Undefined variable: elements in /usr/share/pear/Bartlett/PHP/CompatInfo/Report/Extension.php on line 48

Call Stack:
    0.0001     238560   1. {main}() /usr/bin/phpci:0
    0.0015     422328   2. PHP_CompatInfo_CLI::main() /usr/bin/phpci:31
    0.0078    1068312   3. PHP_CompatInfo_CLI::factory() /usr/share/pear/Bartlett/PHP/CompatInfo/CLI.php:706
    0.0080    1084744   4. PHP_CompatInfo_Report_Full->__construct() /usr/share/pear/Bartlett/PHP/CompatInfo/CLI.php:742
    1.2985   19155416   5. PHP_CompatInfo_Report->__construct() /usr/share/pear/Bartlett/PHP/CompatInfo/Report/Full.php:69
    1.2985   19163408   6. PHP_CompatInfo_Report_Extension->generate() /usr/share/pear/Bartlett/PHP/CompatInfo/Report.php:118

Time: 0 seconds, Memory: 19.25Mb

Required PHP 5.3.0 (min)

Use array_key_exists instead of isset in Filter

It seems that here array_key_exists() (in combination with is_array) should be used instead of isset(). Because "isset($values['versions'])" evaluates to "true" when $values is a string, but then "$values['versions'][2]" expression causes fatal error like this:

Cannot use string offset as an array in /usr/share/php5/PEAR/Bartlett/PHP/CompatInfo/Filter.php on line 69

Code example:

$options = array('recursive' => true);
$phpci = new PHP_CompatInfo($options);
$phpci->parse('/some/path');
$extensions = $phpci->getExtensions();

improve the extension report render

extension report should not display the 0.0 version when extension has none version number

$ php --re mbstring | head -1

Extension [ <persistent> extension #32 mbstring version <no_version> ] {

Actual result :

-------------------------------------------------------------------------------
PHP COMPAT INFO EXTENSION SUMMARY
-------------------------------------------------------------------------------
  EXTENSION                             EXT min/Max       PHP min/Max     COUNT
-------------------------------------------------------------------------------
  Core                                  4.0.0             4.0.0              68
  mbstring                              0.0               4.0.6               2
  pcre                                  0.0               4.0.0              76
  standard                              4.1.0             4.0.0             142
-------------------------------------------------------------------------------
A TOTAL OF 4 EXTENSIONS WERE FOUND
REQUIRED PHP 4.0.6 (MIN)
-------------------------------------------------------------------------------

Expected result :

-------------------------------------------------------------------------------
PHP COMPAT INFO EXTENSION SUMMARY
-------------------------------------------------------------------------------
  EXTENSION                             EXT min/Max       PHP min/Max     COUNT
-------------------------------------------------------------------------------
  Core                                  4.0.0             4.0.0              68
  mbstring                                                4.0.6               2
  pcre                                                    4.0.0              76
  standard                              4.1.0             4.0.0             142
-------------------------------------------------------------------------------
A TOTAL OF 4 EXTENSIONS WERE FOUND
REQUIRED PHP 4.0.6 (MIN)
-------------------------------------------------------------------------------

pecl/http version 2.x

Hi

pecl/http extension version 2.0.1 is released http://pecl.php.net/package/pecl_http

This is a totally new API (using namespace).
So Reference is broken, but I don't see how to set all functions/classes with max extension version, and add new ones with min version.

Freeze while scanning a big project

I tried to scan some big projects for example Symfony 2.1-2.2 and the process stops on 3200-3300 file. I tested on PHP 5.3 on Ubuntu and FreeBSD and had the same result.

"classMemberAccessOnInstantiation" mistake detecting?

Hi, I installed php-compat-info ver 2.2.1.
currently, seems to be detecting as "class member access on instantiation" incorrectly.

sample code is here.

<?php
class MethodReflection
{
    public function getParameters()
    {  
        return new ArrayObject(array($this->getA()->getB()));
    }
}   

require_once 'Bartlett/PHP/CompatInfo.php';
$compatinfo = new PHP_CompatInfo(array('cacheDriver' => 'Null'));
$compatinfo->parse(__FILE__);
$info = current($compatinfo->toArray());
var_dump($info["versions"]);

output:

array(2) {
  [0]=>
  string(5) "5.4.0"
  [1]=>
  string(0) ""
}

( I found this issue at investigation of Zend Framework2.)

phpci print --report token /path/to/zf2/library/Zend/Code/Reflection/

Namespace issue (again)

WIth phpci 2.13.2, a analysis of https://github.com/kriswallsmith/assetic reports some strange things, like:

PHP COMPAT INFO FUNCTION SUMMARY
  Assetic\Cache\apc_delete                                5.3.0               1
  Assetic\Cache\apc_exists                                5.3.0               1
  Assetic\Cache\apc_fetch                                 5.3.0               1
  Assetic\Cache\apc_store                                 5.3.0               1

Should be "apc_delete", from apc extension.

And

PHP COMPAT INFO CONSTANT SUMMARY
C Assetic\Filter\PHP_WINDOWS_VERSION_MAJOR
                                    Core-5.3.0        5.3.0               1

Improve the global report render

It is a non sense to display such global report :

-------------------------------------------------------------------------------
PHP COMPAT INFO GLOBAL SUMMARY
-------------------------------------------------------------------------------
  GLOBAL                                                  PHP min/Max     COUNT
-------------------------------------------------------------------------------
  DOCUMENT_ROOT                         $_SERVER-4.1.0    4.1.0               1
  PATH_TRANSLATED                       $_SERVER-4.1.0    4.1.0               1
-------------------------------------------------------------------------------
A TOTAL OF 2 GLOBALS WERE FOUND
REQUIRED PHP 4.1.0 (MIN)
-------------------------------------------------------------------------------

We should have this expected result :

-------------------------------------------------------------------------------
PHP COMPAT INFO GLOBAL SUMMARY
-------------------------------------------------------------------------------
  GLOBAL                                                  PHP min/Max     COUNT
-------------------------------------------------------------------------------
  DOCUMENT_ROOT                         $_SERVER          4.1.0               1
  PATH_TRANSLATED                       $_SERVER          4.1.0               1
-------------------------------------------------------------------------------
A TOTAL OF 2 GLOBALS WERE FOUND
REQUIRED PHP 4.1.0 (MIN)
-------------------------------------------------------------------------------

The minimum/maximum Extension versions must be displayed only for reports that show the EXT min/Max column

Replace the git RCS keywords at packaging time

This will allow to improve identification of the latest file version.

For example we will have :

* @version  GIT: $Id: CompatInfo.php bcfe5eb 2012-11-26 16:17:32 +0100 Laurent Laville $ 

Rather than just :

* @version  GIT: $Id$

A phing build file will do the job with an enhance version of PearPackageFileSet typedef [1]

[1] phingofficial/phing#174

Not on packagist?

Is there a reason why you haven't submitted phpcompatinfo to packagist yet?
I use composer global for my php related tools, and I would like to avoid adding a custom repository...

Configuration file "" does not exist

When I run analyzer:list I'll see the following in my console:

$ phpcompatinfo-3.0.0RC1-2-gd181e6c.phar analyser:list



  [Exception]                             
  Configuration file "" does not exists.  



analyser:list

I could fix that issue with the following:

$ export COMPATINFO=/home/becker/github/php-compat-info/bin/compatinfo.json
$ phpcompatinfo-3.0.0RC1-2-gd181e6c.phar analyser:list
 Analyser Name Analyser Class                                 
 Class         Bartlett\CompatInfo\Analyser\ClassAnalyser     
 Constant      Bartlett\CompatInfo\Analyser\ConstantAnalyser  
 Extension     Bartlett\CompatInfo\Analyser\ExtensionAnalyser 
 Function      Bartlett\CompatInfo\Analyser\FunctionAnalyser  
 Interface     Bartlett\CompatInfo\Analyser\InterfaceAnalyser 
 Namespace     Bartlett\CompatInfo\Analyser\NamespaceAnalyser 
 Trait         Bartlett\CompatInfo\Analyser\TraitAnalyser

I'll guess there is no config file compiled into the .phar package.

Also have a look at the code where it checks for a configuration file:
https://github.com/llaville/php-compat-info/blob/802b97a7972eb91185670c29baf020ee78dcdcf6/src/Bartlett/CompatInfo/ConsoleApplication.php#L105

type hinting in function prototype

When a function use class type hinting, this should be reported

Ex :
public function __construct(PDO $db)

Should report php-pdo extension and PDO class.

class not detected and bad version

in
$a = new \foo();
$b = new bar()

Only "bar" is reported

N.B. this should be reported as requiring php >= 5.3.0 because of namespace use.

Current report

A TOTAL OF
1 CLASSE(S) 1 FUNCTION(S)
WERE FOUND IN 1 FILE(S)

REQUIRED PHP 4.0.0 (MIN)

missing man page

It will be great to have a man page for phpci command

I know the documentation is provided and quite complete, but this is still a common practice (and a packaging requirement) for all command / config file.

False positive classMemberAccessOnInstantiation detection ?

Hello

Today I scanned MantisBT with your tool, and noticed that when processing one of our bundled libraries - ezc version 2009.2.1 - it detected a case of classMemberAccessOnInstantiation as shown in the below report (irrelevant parts omitted)

$ phpcompatinfo print ezc/Graph/src/renderer/3d.php -R --report token
PHP_CompatInfo 2.20.0 by Laurent Laville
[...]
-------------------------------------------------------------------------------
  TOKEN                                 EXT min/Max       PHP min/Max     COUNT
-------------------------------------------------------------------------------
  classMemberAccessOnInstantiation      standard-5.4.0    5.4.0               1

[...]

This is in the file '3d.php'.

I had a quick look at the file but did not see any occurrences of member access on instantiation, and anyway it seems unlikely it would be the case, since this library dates back to 2009, and PHP 5.4 did not even exist back then...

So I would guess this is a false positive, could you please check ?

Reports "5.2.0 (min)" on DateTime::diff (which requires 5.3)

When run on a simple script containing only these lines of code :

$datetime1 = new DateTime('2013-09-01');
$datetime2 = new DateTime();
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a jours');

phpcompatinfo reports

PHP_CompatInfo 2.22.0 by Laurent Laville

.

-------------------------------------------------------------------------------
PHP COMPAT INFO REPORT SUMMARY
-------------------------------------------------------------------------------
A TOTAL OF 
 1 EXTENSION 1 CLASS 
WERE FOUND IN 1 FILE
REQUIRED PHP 5.2.0 (MIN) 
-------------------------------------------------------------------------------
Time: 0 ms, Memory: 21.25Mb
-------------------------------------------------------------------------------


Time: 0 ms, Memory: 21.25Mb

Required PHP 5.2.0 (min)

but DateTime::diff requires PHP 5.3.0 min, as the doc states on http://php.net/manual/en/datetime.diff.php

Cannot generate documentation with missing UML diagrams pictures

Since [1] I've implemented the UML diagrams build on fly facility with asciidoc-plantuml filter [2] :

  • asciidoc.py can generate the picture from source texte file
  • a2x toolchain wrapper cannot used the picture generate by the asciidoc-plantuml filter

The reason that a2x tried to search in the source input file directory, while the UML diagrams pictures was written in (output.dir)/ images

Temporary solution (until now) was to copy by hand the pictures PHPCompatInfo_*.png in the source docs/images directory.

[1] 8b4abfe
[2] http://code.google.com/p/asciidoc-plantuml/

cache content depends on installed extension.

When a new PHP extension are installed, a new analysis will use cache and will not report the dependency of the newly installed extension.

Ex:


$ phpci print --recursive --report extension Form-2.0.14/Symfony

Core 4.0.0 309
SPL 0.2 5.0.0 5
ctype 4.0.4 3
date 4.0.0 10
pcre 4.0.0 13
session 4.0.0 3

standard 4.0.0 689

$ yum install php-intl

$ phpci print --recursive --report extension Form-2.0.14/Symfony

Core 4.0.0 309
SPL 0.2 5.0.0 5
ctype 4.0.4 3
date 4.0.0 10
pcre 4.0.0 13
session 4.0.0 3

standard 4.0.0 689

=> intl not detected

$ rm /tmp/phpci_*

$ phpci print --recursive --report extension Form-2.0.14/Symfony

Core 4.0.0 309
SPL 0.2 5.0.0 5
ctype 4.0.4 3
date 4.0.0 10
intl 1.1.0 5.2.4 12
pcre 4.0.0 13
session 4.0.0 3

standard 4.0.0 689


Of course using reference="ALL" which workaround this issue.

inconsistent magic constants detection on PHP 5.2, 5.3 and 5.4

Printing constant report of PHPCI with different PHP versions (5.2.x, 5.3.x, and 5.4.x) gave different results.

For example :

 <?php
 glob(__DIR__ . '/XML/XRD{,/*/}*Test.php', GLOB_BRACE);

___ DIR ___ constant will be parsed as T_STRING token for PHP 5.2, and parsed as T_DIR token for PHP 5.3 and 5.4

So, running this command

phpci print --report constant /tmp/glob.php 

Gave this result in PHP 5.2

-------------------------------------------------------------------------------
PHP COMPAT INFO CONSTANT SUMMARY
-------------------------------------------------------------------------------
  CONSTANT                              EXTENSION         VERSION         COUNT
-------------------------------------------------------------------------------
  GLOB_BRACE                            standard          4.0.0               1
-------------------------------------------------------------------------------
A TOTAL OF 1 CONSTANT(S) WERE FOUND
REQUIRED PHP 4.0.0 (MIN)
-------------------------------------------------------------------------------
Time: 2 seconds, Memory: 7.75Mb
-------------------------------------------------------------------------------

And gave this result with PHP 5.3 and 5.4

-------------------------------------------------------------------------------
PHP COMPAT INFO CONSTANT SUMMARY
-------------------------------------------------------------------------------
  CONSTANT                              EXTENSION         VERSION         COUNT
-------------------------------------------------------------------------------
  __DIR__                               Core              5.3.0               1
  GLOB_BRACE                            standard          4.0.0               1
-------------------------------------------------------------------------------
A TOTAL OF 2 CONSTANT(S) WERE FOUND
REQUIRED PHP 5.3.0 (MIN)
-------------------------------------------------------------------------------
Time: 2 seconds, Memory: 3.75Mb
-------------------------------------------------------------------------------

invalid composer.json file

The added composer.json file is invalid:

composer validate
./composer.json is invalid, the following errors/warnings were found:
authors[1].email : Invalid email
Name "pear-bartlett/PHP_CompatInfo" does not match the best practice (e.g. lower-cased/with-dashes). We suggest using "pear-bartlett/php_compat-info" instead. As such you will not be able to submit it to Packagist.
authors.1.email : invalid value (), must be a valid email address

Also it is a best practice to add your composer.lock file ti the repository, so everyone wo runs composer install will get the exact same package versions as you have used while developing.

Composer fails cause of console_commandline

Hello, I had to add pear.php.net to make it work!

pear-pear.php.ne/console_commandline -> no matching package found

"repositories":
[
    {
        "type": "pear",
        "url": "http://pear.php.net"
    },
    {
        "type": "pear",
        "url": "http://bartlett.laurent-laville.org"
    }
]

phpci phar

It would be nice to have phpci as a standalone phar.
Anything planned?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.