PHP 7.1 - Fatal error - Cannot use lexical variable $value as a parameter name
Just migrated a client's site onto a new server with PHP 7.1.
Upon trying to activate the plugin I am faced with the following error:
Fatal error: Cannot use lexical variable $value as a parameter name in /home/forge/site1/public/wp-content/plugins/gravity-forms-post-updates/gravityforms-update-post.php on line 1021
Also need this to be fixed, I've submitted a pull request.
Solution for PHP 7.1 and above. Change row 1021 in file gravityforms-update-post.php
From: add_filter( 'gform_field_value_' . $field['inputName'], function($value) use($value) { return $value; } );
To: add_filter( 'gform_field_value_' . $field['inputName'], function($v) use($value) { return $v; } );
Hi, sorry I think maybe I'm not in the right place for that but I have this code for pre-populate Gravity Forms (using cookies) but it's not compatible with PHP 7.1 (only PHP 7.0). Can you help me rewrite that to work properly with PHP 7.1. Sorry, I'm not a coder. Here is de code:
`/* ----- create cookies to remember items for auction gravity forms ----- */ add_action("gform_pre_submission", "pre_submission_handler"); function pre_submission_handler($form_meta) { $saveVars = array("fname", "lname", "addr1", "addr2", "city", "state", "zip", "country", "zip", "phone", "email", "empresa", "curso", "perfil"); foreach($form_meta["fields"] as $field) { if( $field["allowsPrepopulate"] ){ if( is_array($field["inputs"]) ){ foreach($field["inputs"] as $sub){ $val = $POST["input" . str_replace(".", "", $sub["id"])]; setcookie("gf".$sub["name"], $val, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true); } }else{ $val = $POST["input" . $field["id"]]; setcookie("gf_".$field["inputName"], $val, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true); } } } }
add_filter("gform_pre_render", "add_auto_update_filters"); $contego_callbacks = array(); function add_auto_update_filters($form){ foreach($form["fields"] as &$field){ if( $field["allowsPrepopulate"] ){ if( is_array($field["inputs"]) ){ foreach($field["inputs"] as $sub){ $fieldName = $sub["name"]; add_filter("gform_field_value_" . $fieldName, function($fieldName) use ($fieldName){ return $COOKIE["gf" . $fieldName]; }); } }else{ $fieldName = $field["inputName"]; add_filter("gform_field_value_" . $fieldName, function($fieldName) use ($fieldName){ return $COOKIE["gf" . $fieldName]; }); }
}
}
return $form;
}`
In PHP 7.1 return that I can't use lexical variable $fieldName as a parameter name in line 28.
Huge thanks for your help.
It doesn't look as if this is being actively updated? I'm thinking of setting up a fork of it with the change suggested by @bagendahl Would that be useful.
Been a while since I've mucked about with WordPress, can plugins be updated via github now or is it still the crusty svn repo system?
I'm not familiar with gravity-forms-post-updates,
but perhaps you might find answer in https://stackoverflow.com/a/19432335/351900 recursive function copying $this:
class Foo {
public function bar() {
$that = $this;
return function() use ($that) {
print_r($that);
};
}
}
Notice:
http://php.net/manual/en/functions.anonymous.php From PHP 7.1, these variables must not include superglobals, $this, or variables with the same name as a parameter.