Sterc / FormIt

A dynamic form processing Snippet for MODX Revolution
https://docs.modx.com/current/en/extras/formit
33 stars 58 forks source link

PHP 7 Compatibility #98

Closed stackcoder closed 7 years ago

stackcoder commented 8 years ago

FormIt isn't PHP 7 ready. I'm not sure exactly which functionality is broken if you execute this extra in a PHP 7 environment, but if you depend on it you should not update right now.

Result of php7cc v1.1.0

File: /core/components/formit/model/recaptcha/formitrecaptcha.class.php
> Line 46: Possible object property creation during by-reference assignment
    $this->modx =& $formit->modx;

File: /core/components/formit/model/formit/fihooks.class.php
> Line 86: Possible object property creation during by-reference assignment
    $this->modx =& $formit->modx;
> Line 430: Possible adding to array on the last iteration of a by-reference foreach loop
    $fields[$vKey] = $vValue;

File: /core/components/formit/model/formit/module/fimodule.class.php
> Line 42: Possible object property creation during by-reference assignment
    $this->modx =& $formit->modx;

File: /core/components/formit/model/formit/fidictionary.class.php
> Line 54: Possible object property creation during by-reference assignment
    $this->modx =& $formit->modx;

File: /core/components/formit/model/formit/fivalidator.class.php
> Line 66: Possible object property creation during by-reference assignment
    $this->modx =& $formit->modx;
> Line 421: Removed function "ereg" called
    ereg($pattern, $value);
> Line 433: Removed function "ereg" called
    ereg($pattern, $local_array[$i]);
> Line 443: Removed function "ereg" called
    ereg($pattern, $email_array[1]);
> Line 454: Removed function "ereg" called
    ereg($pattern, $domain_array[$i]);

File: /core/components/formit/model/formit/firequest.class.php
> Line 68: Possible object property creation during by-reference assignment
    $this->modx =& $formit->modx;

File: /core/components/formit/elements/snippets/snippet.formitautoresponder.php
> Line 57: Possible adding to array on the last iteration of a by-reference foreach loop
    $fields[$k] = $v['name'];
> Line 63: Possible adding to array on the last iteration of a by-reference foreach loop
    $fields[$vKey] = $vValue;
> Line 70: Possible adding to array on the last iteration of a by-reference foreach loop
    $fields[$k] = $newValue;

Further I did some code search and noticed:

File: /core/components/formit/elements/snippets/snippet.formitsaveform.ph

Line 83: list() no longer assigns variables in reverse order

@@ -80,8 +80,8 @@ if($fieldNames){
     $fieldLabels = array();
     $formFieldNames = explode(',', $fieldNames);
     foreach($formFieldNames as $formFieldName){
-        list($name, $label) = explode('==', $formFieldName);
-        $fieldLabels[trim($name)] = trim($label);
+        $parts = explode('==', $formFieldName);
+        $fieldLabels[trim($parts[0])] = trim($parts[1]);
     }
     foreach ($dataArray as $key => $value) {
         if($fieldLabels[$key]){

File: /core/components/formit/model/formit/module/fistateoptions.class.php

Line 78: Changes to the handling of indirect variables, properties, and methods

foreach ($this->states as $stateKey => $stateName) {
    $stateArray = array(
        'text' => $stateName,
        'value' => $$selectedKey,
        'selected' => '',
    );
    if ($selected == $$selectedKey) {
        $stateArray['selected'] = $selectedAttribute;
    }
    $this->list[] = $this->formit->getChunk($tpl,$stateArray);
}

List of Backward incompatible changes: https://secure.php.net/manual/de/migration70.incompatible.php

hugopeek commented 7 years ago

@joeke I see this issue just celebrated its 1st birthday. Has this been investigated already, together with #92? Seems like a pretty serious flaw if FormIt is not fully compatible with PHP 7, as more and more people will be making that switch now..

joeke commented 7 years ago

@hugopeek I'm afraid this issue lost our attention a bit. I did apply the fix for formitsaveform by removing the list() function (thanks for that @stackcoder). I'm looking into the other compatibility issues now.

joeke commented 7 years ago

@stackcoder @hugopeek All the PHP7 compatibility issues should be resolved now (See https://github.com/Sterc/FormIt/commit/4c728757a4ad05ee6822014c084369a1c5017d04, https://github.com/Sterc/FormIt/commit/d0636355a868bc70d6bb0dd292f97d00f497a9a7 and https://github.com/Sterc/FormIt/commit/a4fbd70cf9f8e98deba0cec449318f63baa39638). All fixes will be included in the upcoming 3.0.3 release.

hugopeek commented 7 years ago

Excellent work @joeke! It's these little invisible fixes that keep things running safely and smoothly for everyone :)