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.


21 months ago

#2 @cristiano.zanca
21 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
21 months ago

I incorrectly informed @cristiano.zanca that this was a bug because in the test I did I included the PHP Version string :( .

Example:

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

Instead, the correct test doing this:

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

returns the expected true value.

For future proofing against possible string issues we _could_ still use the constants as mentioned below but for all intents and purposes this does not appear to be a bug right now.

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'], '>=' ) );
Last edited 21 months ago by nerrad (previous) (diff)

#5 @swissspidy
21 months ago

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