WordPress.org

Make WordPress Core

#46411 closed defect (bug) (worksforme)

Requirements PHP Version plugin error with False positive

Reported by: cristiano.zanca Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.2
Component: Plugins Keywords: has-screenshots
Focuses: Cc:

Description

Hi, in a local LEMP with NGINX and no APACHE,
phpinfo() show this PHP version PHP Version 7.2.15-1+0~20190209065123.16+stretch~1.gbp3ad8c0

https://i.imgur.com/DBiiC2J.png

I want to install and test my plugin https://wordpress.org/plugins/woo-fattureincloud/ that has minimum requirements PHP 7.1

=== WooCommerce Fattureincloud ===
Contributors: cristianozanca
Tags: fattureincloud, fattura elettronica, fatturazione elettronica
Requires at least: 4.6
Tested up to: 5.1
Requires PHP: 7.1

and an error is displayed
https://i.imgur.com/WO4F0ky.png

Change History (5)

This ticket was mentioned in Slack in #core-php by cristiano.zanca. View the logs.


13 months ago

#2 @cristiano.zanca
13 months ago

Mark Wolinski says it may be the additional text on the PHP version number that’s causing the issue, @nerrad add that "The check is being done via:
version_compare( phpversion(), $plugin['requires_php'], '>=' )"

#3 @nerrad
13 months ago

The issue appears to be that the version_compare check fails with certain php version strings reported by phpversion().

Example:

var_dump( version_compare( 'PHP Version 7.2.15-1+0~20190209065123.16+stretch~1.gbp3ad8c0', '7.1', '>=' ) );

Reports false.

So there will need to be some sanitization of the string returned by phpversion()

Alternatively, using the php version constants might be better here: PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION. That will ensure we're only comparing on the important values, so something like:

$server_php_version = implode( '.', array( PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION ) );
$compatible_php = ( empty( $plugin['requires_php'] ) || version_compare($server_php_version, $plugin['requires_php'], '>=' ) );
Version 0, edited 13 months ago by nerrad (next)

#5 @swissspidy
13 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.