Buy Now
Sign in

Cannot use string offset as an array

benjimckinney , August 11 2016, 01:28
B
benjimckinney 1
August 11 2016, 01:28 #361160
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 65
August 11 2016, 10:30 #361163
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
If you'd like to buy me a coffee or two, thank you very much
M
Max92 1
February 02 2017, 14:01 #364780
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 65
February 02 2017, 14:17 #364781
 1
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
    If you'd like to buy me a coffee or two, thank you very much
    W
    Warren.Kessler 8
    March 29 2017, 16:01 #366317
    Do you know if this has been addressed in the latest version? I am having the same issue. Thanks.
    GreyHead 65
    March 29 2017, 19:44 #366329
    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
    If you'd like to buy me a coffee or two, thank you very much
    admin 33
    March 30 2017, 08:03 #366341
    Hi Warren,

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

    Best regards,
    Max
    W
    Warren.Kessler 8
    March 30 2017, 16:24 #366362
    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 33
    March 30 2017, 18:05 #366367
    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
    J
    jmcd73 11
    June 08 2017, 08:47 #369088
     2
    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 15
    July 19 2017, 19:19 #370687
    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 65
    July 21 2017, 10:03 #370745
    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
    If you'd like to buy me a coffee or two, thank you very much
    H
    HDsports 1
    December 05 2017, 13:55 #373938
    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 33
    December 05 2017, 19:29 #373942
    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