gravity-forms-post-updates icon indicating copy to clipboard operation
gravity-forms-post-updates copied to clipboard

PHP 7.1 - Fatal error - Cannot use lexical variable $value as a parameter name

Open mdeloughry opened this issue 8 years ago • 5 comments

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

mdeloughry avatar Feb 13 '17 15:02 mdeloughry

Also need this to be fixed, I've submitted a pull request.

andylobel avatar Aug 15 '17 21:08 andylobel

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; } );

bagendahl avatar Oct 09 '17 10:10 bagendahl

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.

amesdigital avatar Jan 02 '18 09:01 amesdigital

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?

BenAttenborough avatar Mar 16 '19 15:03 BenAttenborough

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.

laukstein avatar Apr 05 '19 13:04 laukstein