【问题标题】:Undefined property: stdClass:: on Object [closed]未定义的属性:stdClass :: on Object [关闭]
【发布时间】:2021-02-18 22:08:00
【问题描述】:

我到处都在做这种事情,没有任何麻烦,但这次没有成功。

var_dump($fields);

结果:

object(stdClass)[880]
  public 'teacher_model' => 
    object(Backend\Classes\FormField)[754]
      public 'fieldName' => string 'teacher_model' (length=13)
      public 'arrayName' => string 'Shooting' (length=8)
      public 'idPrefix' => string 'Form' (length=4)
      public 'label' => string 'Modèle enseignant' (length=18)
      public 'value' => string '' (length=0)
      public 'valueFrom' => string 'teacher_model' (length=13)
      public 'defaults' => null
      public 'defaultFrom' => null
      public 'tab' => string 'quendistudio.dispose::lang.tab.report' (length=37)
      public 'type' => string 'text' (length=4)
      public 'options' => null
      public 'span' => string 'storm' (length=5)
      public 'size' => string 'large' (length=5)
      public 'context' => null
      public 'required' => boolean false
      public 'readOnly' => boolean false
      public 'disabled' => boolean false
      public 'hidden' => boolean false
      public 'stretch' => boolean false
      public 'comment' => string '' (length=0)
      public 'commentPosition' => string 'below' (length=5)
      public 'commentHtml' => boolean false
      public 'placeholder' => string '' (length=0)
      public 'attributes' => null
      public 'cssClass' => string 'col-xs-12 col-md-6 col-lg-4' (length=27)
      public 'path' => null
      public 'config' => 
        array (size=5)
          'label' => string 'Modèle enseignant' (length=18)
          'span' => string 'storm' (length=5)
          'cssClass' => string 'col-xs-12 col-md-6 col-lg-4' (length=27)
          'type' => string 'text' (length=4)
          'tab' => string 'quendistudio.dispose::lang.tab.report' (length=37)
      public 'dependsOn' => null
      public 'trigger' => null
      public 'preset' => null

看起来不错,但现在有人解释一下吗:

var_dump($fields->teacher_model);

结果:

未定义属性:stdClass::$teacher_model

为什么???

【问题讨论】:

  • 试试 $fields[0]->teacher_model

标签: php laravel object octobercms


【解决方案1】:

所有这些都是通过一个函数执行的。我刚刚发现我的$fields 对象是在填充和我的函数之前创建的,所以我的 var_dump 会被执行多次,即使我只看到最后一次递归,我也可以看到 var_dump($fields) 的结果,只是因为之前的所有var_dump 的递归不会触发任何错误。因此,对于对象属性的可访问性,在 Laravel/October CMS 中,有时您必须在某些条件下执行此操作。我之前放过这个,效果很好。

if (!isset($fields->teacher_model)) {
    return;
}

【讨论】:

    【解决方案2】:

    检查您的 php 版本是否与 octobercms 版本兼容

    【讨论】:

      猜你喜欢
      • 2020-12-03
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 2016-04-20
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多