Givewp: Incompatibility with PHP 7.1

Created on 6 Jan 2017  路  4Comments  路  Source: impress-org/givewp

Issue Overview

Users currently cannot use Give with PHP 7.1

Expected Behavior

We should be current with the latest available PHP version. Siteground for example offers a one-click upgrade to PHP 7.1.

Current Behavior

If a user upgrades to PHP 7.1 Give works generally, but not on the Form Edit screen. This is what they see:
image

`Fatal error: Uncaught Error: [] operator not supported for strings in .../wp-content/plugins/give/includes/formatting.php:443 Stack trace: #0 .../wp-content/plugins/give/includes/libraries/cmb2/includes/CMB2_Base.php(283): give_cmb_amount_field_render_row_cb(Array, Object(CMB2_Field)) #1 .../wp-content/plugins/give/includes/libraries/cmb2/includes/CMB2_Base.php(258): CMB2_Base->do_callback('give_cmb_amount...') #2 .../wp-content/plugins/give/includes/libraries/cmb2/includes/CMB2_Base.php(235): CMB2_Base->get_param_callback_result('render_row_cb') #3 .../wp-content/plugins/give/includes/libraries/cmb2/includes/CMB2_Field.php(759): CMB2_Base->peform_param_callback('render_row_cb') #4 .../wp-content/plugins/give/includes/libraries/cmb2/includes/CMB2.php(315): CMB2_Field->render_field() #5 .../wp-content/plugins/give/includes/librari in .../wp-content/plugins/give/includes/formatting.php on line 443

Steps to Reproduce (for bugs)

The error can currently be seen on this test site (which our team has credentials to internally):
http://php7.mattcromwell.com/donations/standard-form/

That site has been upgraded to PHP 7.1 via Siteground's one-click PHP Version manager.

All 4 comments

Cause

Cause of the error can be found here: https://github.com/WordImpress/Give/blob/master/includes/formatting.php#L437-L443

This error is caused by $attributes_string being defined as an empty string on line 437 and then used as an array on line 443. PHP 7.1 doesn't like that.

Quick Fix

The quick fix is to change the following on line 437 from:
$attributes_string = ''; to $attributes_string = array();

A proper fix will be incorporated into the next release. For clarity, the variable should not be named $attributes_string if it begins as an array.

Note the error is caused by a CMB2 function that doesn't exist in Give 1.8.0 as meta fields are now being handled differently. Need @DevinWalker to weigh in on whether a point release should address this sooner. The error prevents anyone on PHP 7.1 from creating a donation form.

@kevinwhoffman We can not user short tag for now because this will not work in PHP 5.3.
[] short array syntax introduced in PHP 5.4.

As of PHP 5.4 you can also use the short array syntax, which replaces array() with [].

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

@ravinderk Thanks for the heads up. I edited my fix above to use array() instead.

Was this page helpful?
0 / 5 - 0 ratings