-1

I get a debug notice in Elementor Addon. Undefined variable $out, but it works for me. I can't figure out what I'm doing wrong.

Guys, please help!

Thanks a lot!

NOTICE:

Undefined variable: out on line 1077 in file /Applications/MAMP/htdocs/...

    private function content($content,$disp) {
        foreach ($content as $item){
            $img = tmaddon_bg_images($item['img']['id'],$settings['img_size']);
            $title = $item['title'] ? '<span class="tm-title"><p>'.$item['title']. '</p></span>' : '';
            $subtitle = $item['subtitle'] ? '<span class="tm-subtitle"><p>'.$item['subtitle']. '</p></span>' : '';
            $label_text = $item['label-text'] ? '<span>'.$item['label-text']. '</span>' : '';
            // $icon = $item['icon'] ? '<span class="item-icon"><i class="'.$item['icon'].'"></i></span>' : '';
            $icon = $item['icon'] ? '<div class="read-more-btn link link--arrowed">
                <svg class="arrow-icon" xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="9 9 32 32">
                    <g fill="none" stroke="" stroke-width="1.5" stroke-linejoin="round" stroke-miterlimit="10">
                        <circle class="arrow-icon--circle" cx="25" cy="25" r="15.12"></circle>
                        <i class="arrow-icon--arrow '.$item['icon'].'"></i>
                    </g>
                </svg>
            </div>' : '';
            $carcls = $disp == 'carousel' ? 'swiper-slide' : $disp;
            $url = $item['url']['url'];
            $ext = $item['url']['is_external'];
            $nofollow = $item['url']['nofollow'];
            $url = ( isset($url) && $url ) ? 'href='.esc_url($url). '' : '';
            $ext = ( isset($ext) && $ext ) ? 'target= _blank' : '';
            $nofollow = ( isset($url) && $url ) ? 'rel=nofollow' : '';
            $link = $url.' '.$ext.' '.$nofollow;
            $btn = $url ? '<a '.$link.' class="fullink"></a>' : '';
    
            $out .= '
             <div class="items '.$carcls.'">
                <div class="item-wrap">
                    <div '.$img.' class="item-image lazyload">
                        '.$btn.'
                        <div class="label-text">'.$label_text.'</div>
                        <div class="item-content">
                            '.$icon.$title.$subtitle.'
                        </div>
                    </div>
                </div>
            </div>
            ';
        }
        return $out;        
    }
}
trincot
  • 317,000
  • 35
  • 244
  • 286

1 Answers1

2

The reason for the warning is that when $out is used for the first time, it refers to itself:

    $out .= '....'

This is saying to append a string to $out. But as $out was never initialised, it is not clear to what the string should be appended.

To remove this warning, initialise $out before the start of the loop:

$out = '';
foreach ($content as $item){
   // ...etc
trincot
  • 317,000
  • 35
  • 244
  • 286