0

This code give me an Illegal string offset ‘gfmem_type’ in /home/customer/www/.... on line 702. Line 702 is the one starting with "if" here.

I think that this is strange because the code works and I can echo the $settings['gfmem_type'] (Gives me "profile") and I can print_r the $settings where I can find the 'gfmem_type'. If I did not found the gfmem_type I can understand the error, but its all there.

        public function profile_fields( $form ) {
            $settings = $this->get_form_settings( $form );
            if ($settings['gfmem_type'] == 'profile') {
        ...

Why do I get the error?

Fredrik
  • 357
  • 3
  • 13
  • 1
    `if (isset($settings['gfmem_type']) && $settings['gfmem_type'] == 'profile')` – glinda93 Jan 28 '21 at 07:27
  • you can use `var_dump($settings)` to investigate – eis Jan 28 '21 at 07:29
  • and also, prefer `===` comparisons in PHP unless you have really, really good reason to do otherwise – eis Jan 28 '21 at 07:29
  • check if key is exist then check next condition " if(array_key_exists("gfmem_type",$settings) and $settings['gfmem_type'] == 'profile') " – Muhammad Kamran Jan 28 '21 at 07:30
  • @bravemaster is right, so you basically get that error simply because $settings['gfmem_type'] does not exist. Indeed do the check first (isset, not array_key_exists which is technically ok but not pretty) and then access it when it exists – Ray Jan 28 '21 at 07:33

0 Answers0