0

So I'm trying to figure out, why PHP 7.1.1 throws me an error for the following _construct function:

    function __construct( $field = array(), $value ='', $parent ) {

    //parent::__construct( $parent->sections, $parent->args );
    $this->parent = $parent;
    $this->field = $field;
    if (empty($this->field['class']))
        $this->field['class'] = '';
    $this->value = $value;
    $this->args = $parent->args;
}

And I get this error.

Warning: Illegal string offset 'class' in D:\Servers\Web Server\les.local.dev\wp-content\themes\mts_onepage\options\fields\layout\field_layout.php on line 34

Warning: Cannot assign an empty string to a string offset in D:\Servers\Web Server\les.local.dev\wp-content\themes\mts_onepage\options\fields\layout\field_layout.php on line 34

If I remove the IF part, where it checks if $this->field['class'] is empty or not, the error disappears.

I know PHP 7.1 changed how arrays work kinda, but I still don't get it.

Andor Nagy
  • 174
  • 4
  • 15
  • 1
    Please add the line that calls the constructor (especially the $field value). – matfax Mar 24 '17 at 14:12
  • 1
    `var_dump($field)` - I guess that `$field` is not an array – simon Mar 24 '17 at 14:14
  • If I define $field as an array, inside the _construct function, and not in the arguments, it works. – Andor Nagy Mar 24 '17 at 14:17
  • 1
    maybe `if (isset($this->field['class'])` instead of `empty` you could even replace `if (empty($this->field['class']) $this->field['class'] = '';` with `$this->field['class'] = $this->field['class'] ?? '';` – Unex Mar 24 '17 at 15:15

0 Answers0