未定义的变量,但对我有用。调试通知

发布于 2025-02-12 05:14:21 字数 2732 浏览 3 评论 0原文

我在Elementor Addon中收到了调试通知。未定义的变量$ out,但对我有用。 我不知道我在做什么错。

伙计们,请帮忙!

非常感谢!

注意:

未定义的变量:在文件/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;        
    }
}

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;        
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹苦笑 2025-02-19 05:14:21

警告的原因是,当第一次使用$ of时,它是指自身:

    $out .= '....'

这说明字符串将字符串附加到$ ut。但是,由于$ out从未初始化,因此尚不清楚该字符串应附加。

要删除此警告,请在循环开始之前初始化$ out

$out = '';
foreach ($content as $item){
   // ...etc

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文