[wp-trac] [WordPress Trac] #46411: Requirements PHP Version plugin error with False positive

WordPress Trac noreply at wordpress.org
Mon Mar 4 15:08:34 UTC 2019


#46411: Requirements PHP Version plugin error with False positive
-----------------------------+------------------------------
 Reporter:  cristiano.zanca  |       Owner:  (none)
     Type:  defect (bug)     |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Plugins          |     Version:  trunk
 Severity:  normal           |  Resolution:
 Keywords:  has-screenshots  |     Focuses:
-----------------------------+------------------------------

Comment (by nerrad):

 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'], '>=' ) );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46411#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list