Buy Now
Sign in

Cannot use string offset as an array

benjimckinney , August 11 2016
B
benjimckinney
I am using PHP Version 7.1.0alpha3

I just downloaded and installed the latest Chronoforms to my website. However, when i try to create a new form and then click save I get this message: "Cannot use string offset as an array" The only option given is to return to Control Panel. Can anyone tell me how to fix this?? Looks like this:



Please help...thank you!
GreyHead
Hi benjimckinney,

Not the slightest idea, I'm running 7.0.9 with no problems.

If you set the site Error Reporting to Maximum or Developer do you get a more useful message?

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
M
Max92
I have the same problem im using 7.1 php version and get the same error. Max reporting don't show anything else it's same as on the first screenshot the previous guy posted. i can't save the email that i enter.
GreyHead
Hi Max92,

This is a result of a change in PHP 7.1 basically you can't use e.g. $array
  • = 'some string'; without first declaring $array as an array. So it needs to be
    <?php
    . . .
    $array = array(); // this line wasn't required in 7.0
    . .
    $array
  • = 'some string';
    . . .
    ?>I have no idea where in the code the error might be arising and the host for my test site doesn't yet offer PHP 7.1

    I expect Max will fix this in a future release, for the moment the only solution I know of is to revert to PHP 7.0

    Bob
    ChronoForms technical support
    If you'd like to buy me a coffee or two, thank you very much
    W
    Warren.Kessler
    Do you know if this has been addressed in the latest version? I am having the same issue. Thanks.
    GreyHead
    Hi Warren,

    Not as far as I know, My host still doesn't offer 7.1 so I'm not easily able to check exactly where the problems are. PHP 7.0 does not have this problem.

    Bob
    ChronoForms technical support
    If you'd like to buy me a coffee or two, thank you very much
    admin
    Hi Warren,

    Could you please download v6 and test on PHP 7.1 and let us know how it works ?

    Best regards,
    Max
    Max
    If your main question got answered then please mark the answer using the button!​
    ​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
    W
    Warren.Kessler
    Yes, it did work. I didn't thoroughly test it since I have no forms built for v6 but it did not give me the "Cannot use string offset as an array" error.
    admin
    Hi Warren,

    Great, you can take a v5 form backup and restore it on v6, but the setup section will not be imported, and some settings under the designer too, but it will save you some work.

    Best regards,
    Max
    Max
    If your main question got answered then please mark the answer using the button!​
    ​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
    J
    jmcd73
    As far as I can tell the problem is in libraries/cegcore/libs/arr.php in the setVal function near line 60. It is using eval and now PHP 7.1.5 as mentioned above doesn't like an array index being assigned to a string value...


    So to fix it use some code found at https://stackoverflow.com/questions/7465043/how-to-dynamically-access-values-in-a-variably-multidimensional-array

    I have modified it so it works with chronoforms v5.

       //set some array value at the given path and return the modified array back
        public static function setVal($array, $indexes, $value){
            if(is_array($array)){

                // eval('$array["'.implode('"]["', $indexes).'"] = $value;');
                self::assign($array, $indexes, $value);

            }
            return $array;
        }


        private static function assign(&$array, $keys, $value) {
            $last_key = array_pop($keys);
            $tmp = &$array;
            foreach($keys as $key) {
                if(!isset($tmp[$key]) || !is_array($tmp[$key])) {
                    $tmp[$key] = array();
                }
            $tmp = &$tmp[$key];
            }
            $tmp[$last_key] = $value;
            unset($tmp);
        }

    S
    sujet
    Hello jmcd73,

    i have the same Problem.
    Can you please give me your arr.php File or the complete File Code please.
    I dont know exactly what i must change in this File?
    I am not so firm with it.

    Thanks
    GreyHead
    Hi sujet,

    You need to edit the file /libraries/cegcore/libs/arr.php and look for this code at about line 57

      //set some array value at the given path and return the modified array back
      public static function setVal($array, $indexes, $value){
        if(is_array($array)){
          eval('$array["'.implode('"]["', $indexes).'"] = $value;');
        }
        return $array;
      }
      //flatten multi dimensional array
    . . .

    You need to replace this with the two functions here:
    //set some array value at the given path and return the modified array back
    public static function setVal($array, $indexes, $value){
    if(is_array($array)){
    self::assign($array, $indexes, $value);
    }
    return $array;
    }

    private static function assign(&$array, $keys, $value) {
    $last_key = array_pop($keys);
    $tmp = &$array;
    foreach($keys as $key) {
    if(!isset($tmp[$key]) || !is_array($tmp[$key])) {
    $tmp[$key] = array();
    }
    $tmp = &$tmp[$key];
    }
    $tmp[$last_key] = $value;
    unset($tmp);
    }
      //flatten multi dimensional array
    . . .

    Bob

    PS I still don't have PHP 7.1 on my test site so can't test this - it's just taken from the earlier post here
    ChronoForms technical support
    If you'd like to buy me a coffee or two, thank you very much
    H
    HDsports
    Hey, is this problem solved?
    i have a problem with chronofrms when i click on "Create Table" than i get the error
    " Cannot use string offset as an array "
    admin
    Hello,

    The issue you have is a different issue on servers which have php 7.1 and should be fixed in the new update scheduled for later this week!

    Best regards
    Max
    If your main question got answered then please mark the answer using the button!​
    ​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!