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

Incompatibility with PHP 7.1 #1377

Closed
mathetos opened this issue Jan 6, 2017 · 4 comments
Closed

Incompatibility with PHP 7.1 #1377

mathetos opened this issue Jan 6, 2017 · 4 comments
Assignees
Milestone

Comments

@mathetos
Copy link
Member

mathetos commented Jan 6, 2017

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.

@mathetos mathetos added the bug label Jan 6, 2017
@kevinwhoffman
Copy link
Contributor

kevinwhoffman commented Jan 6, 2017

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.

@kevinwhoffman
Copy link
Contributor

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.

@ravinderk
Copy link
Collaborator

@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

@kevinwhoffman
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants