Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awareness of compatibility packages #237

Closed
glynnforrest opened this issue Dec 1, 2017 · 14 comments
Closed

Awareness of compatibility packages #237

glynnforrest opened this issue Dec 1, 2017 · 14 comments
Assignees

Comments

@glynnforrest
Copy link

Firstly, thank you for this great tool! I thought I was going to have to write a script to figure out what extensions a project required. I'm glad I can use this tool instead.

Do you think it would be possible for the script to detect usage of 'compat' packages, that bring newer features to older PHP versions?

For example, I have some code that uses random_bytes(), introduced in PHP 7. By requiring paragonie/random_compat I can have it work for older versions. It would be great if php-compat-info could detect this.

I guess this would require parsing the requirements in composer.json to see if any of these packages are being used.

Some package examples:

@llaville llaville mentioned this issue Sep 2, 2020
11 tasks
@llaville llaville self-assigned this Sep 2, 2020
@llaville llaville added this to the 6.0 milestone Sep 2, 2020
@llaville llaville removed this from the 6.0 milestone May 16, 2021
@llaville
Copy link
Owner

llaville commented Mar 9, 2022

Many versions and years later, upcoming release 6.4 will finally include this new feature !

@llaville
Copy link
Owner

I've a prototype available with the new polyfill detection feature.
@glynnforrest Dod you want to contribute to test the new feature in real condition ?

@glynnforrest
Copy link
Author

That's exciting @llaville! Are you looking for me to submit a test case?

@llaville
Copy link
Owner

I'll push the code to a new branch polyfill tomorrow. Your feedback, and any test you could done will be welcome !

@llaville
Copy link
Owner

@glynnforrest Code is available.

We need to optimize process because polyfills initialization take too much time for me.

compatinfo64-polyfills-warmup

Here is an example with PHP CompatInfo 6.4 code scanned

compatinfo64-polyfills

Without polyfills, results are wrong and give PHP 8.0 as min requirements, while with polyfills, results are as expected.

You need to initialized

  • as previous the database db:create, and db:init
  • the polyfills depending of your source code installed : run bin/polyfill-warmup

And run data source code analyse

@llaville
Copy link
Owner

BTW, after a night to think about a better solution, I've in mind, in next days, to include polyfills handle to the https://github.com/llaville/php-compatinfo-db project, and adjust code in CompatInfo.

In the meantime, if somebody want to share is feedback about this feature before it will become official, he will be welcome !

@llaville
Copy link
Owner

Found origin of double time elapsed with bin/polyfill-warmup script (and its uses in ReferenceCollection).

But even without this issue, init time is a bit long, and I'm +1 to include it in Compatinfo-DB now !

polyfills-warmup

Scheduled for PHP CompatInfoDB 4.2.0

@llaville
Copy link
Owner

CompatInfoDB 4.2.x-dev is ready to support polyfills. See commit llaville/php-compatinfo-db@c5ce8ac

@llaville
Copy link
Owner

CompatInfo 6.4.x (with branch polyfill) and commit 9b3a755 use now the CompatInfoDB 4.2.x-dev (branch polyfill) for detection.

NOTE: it won't be necessary in final version of CompatInfoDB 4.2.0 were symfony/polyfill will be added.

To add a polyfill (compatible) like https://github.com/symfony/polyfill/tree/main/src/Php80 do as follow :

  • run db:create
  • run db:polyfill symfony/polyfill-php80 v1.25.0 --php 8.0 -v
  • run db:init

@llaville
Copy link
Owner

llaville commented Apr 1, 2022

Reminder: This report will be closed in 5 days even if I don't receive any feedback !

@glynnforrest
Copy link
Author

Thanks for your work on this @llaville! I can't get this feature working, am I doing something wrong?

Here is an example of trying symfony/polyfill-php80 on php 7.4.

php -v

# PHP 7.4.28 (cli) (built: Mar  1 2022 01:37:04) ( NTS )

Create test.php and try without polyfill:

#!/usr/bin/env php
<?php

var_dump(str_starts_with('foobar', 'foo'));
./test.php

# PHP Fatal error:  Uncaught Error: Call to undefined function str_starts_with()

Add the polyfill:

composer require symfony/polfill-php80 ^1.25.0
  #!/usr/bin/env php
  <?php

+ include 'vendor/autoload.php';
  var_dump(str_starts_with('foobar', 'foo'));
./test.php

# bool(true)

Now analyse with php-compatinfo:

composer require bartlett/php-compatinfo ^6.4-dev

./vendor/bin/phpcompatinfo db:create
./vendor/bin/phpcompatinfo db:init # At least one distribution platform should exist. None available. Run "db:init" command to build one.
./vendor/bin/phpcompatinfo db:polyfill symfony/polyfill-php80 v1.25.0 --php 8.0 -v
./vendor/bin/phpcompatinfo db:create

I see polyfill analysis in the output, but still PHP 8 is required:

image

I tried with:

composer require bartlett/php-compatinfo '^6.4-dev'
composer require bartlett/php-compatinfo 'dev-polyfill'

@llaville
Copy link
Owner

llaville commented Apr 4, 2022

@glynnforrest

  • First, I would like to thanks you to provide a such issue report with full details. It's so rare these days ;-)

  • Second, I would like to clarify status code and procedure to install correctly PHP CompatInfo (6.4.0 upcoming version)

When you try to install source code version from a branch, take care to give the right constaint:

With composer require bartlett/php-compatinfo ^6.4-dev you won't install polyfill code. Checks Composer output that give

- Installing bartlett/php-compatinfo-db (4.2.0): Extracting archive
- Installing bartlett/php-compatinfo (6.4.x-dev c19c87b): Extracting archive

Picking code from branch 6.4

With following constraint

composer require bartlett/php-compatinfo dev-polyfill

You get the right code, verified by Composer output

  - Installing bartlett/php-compatinfo-db (4.2.0): Extracting archive
  - Installing bartlett/php-compatinfo (dev-polyfill 0f3664b): Extracting archive

Now, that Polyfills feature is supported by PHP CompatInfo DB 4.2.0, you don't have to specify the db:polyfill command.
It's for me (maintainer of CompatInfoDB project) and user that want to add new polyfill in database not yet supported.

So, in summary : db:create and db:init is enough !

  • Third you are right there is a little regression with available code, due to Unit tests. Fix will be push in few seconds

@llaville
Copy link
Owner

llaville commented Apr 4, 2022

With commit 5f81d4d, unit tests and analyser:run command works as expected

expected_results_issue237

@llaville llaville changed the title Awareness of 'compat' packages (e.g. paragonie/random_compat) Awareness of compatibility packages Apr 5, 2022
@llaville
Copy link
Owner

llaville commented Apr 5, 2022

I've just opened a discussion #350 to explain how to understand polyfill results

@llaville llaville closed this as completed Apr 6, 2022
llaville added a commit that referenced this issue Apr 6, 2022
* new feature request #237 about polyfill detection

* upgrade to actions/checkout v3

* raise bartlett/php-compatinfo-db constraint to 4.2 minimum to support polyfill feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants