本文介绍了PHP - 试图让非对象的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过所谓的对象属性来遍历项目包含数组:

I'm trying to iterate through an object property called items that contains an array:

foreach ($this->footerList->items as $item)

当我执行语句,我得到一个错误说 - 试图让非对象的财产尽管

When I execute the statement, I get an error saying - "Trying to get property of non-object" even though

var_dump($this->footerList) 

显示, $这个 - > footerList 确实包含项目阵列。

object(FooterModel)#13 (1) 
{ 
    ["items"]=> array(3) 
    { 
        [0]=> array(5) 
        { 
             ["id"]=> string(20) "terms-and-conditions" 
             ["title"]=> string(20) "Terms and Conditions" 
             ["url"]=> string(23) "home/termsandconditions" 
             ["label"]=> string(20) "Terms and Conditions" 
             ["authenticatedOnly"]=> string(5) "false" 
        } 
        [1]=> array(5) 
        { 
             ["id"]=> string(14) "privacy-policy" 
             ["title"]=> string(14) "Privacy Policy" 
             ["url"]=> string(18) "home/privacypolicy" 
             ["label"]=> string(14) "Privacy Policy" 
             ["authenticatedOnly"]=> string(5) "false" 
         } 
    } 
} 

可有人请帮我找出为何循环语句无法解析 $这个 - > footerList->项目

推荐答案

这应该是

foreach ($this->footerList["items"] as $item)

这篇关于PHP - 试图让非对象的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 12:50