phplaravelobjectoctobercms

Undefined property: stdClass:: on Object


I'm doing this kind of thing everywhere without any trouble, but this time with no success.

var_dump($fields);

Result:

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 'One model' (length=18)
      public 'value' => string '' (length=0)
      public 'valueFrom' => string 'teacher_model' (length=13)
      public 'defaults' => null
      public 'defaultFrom' => null
      public 'tab' => string 'some.thing::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 'One model' (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 'some.thing::lang.tab.report' (length=37)
      public 'dependsOn' => null
      public 'trigger' => null
      public 'preset' => null

Seems okay, but now is there somebody to explain that:

var_dump($fields->teacher_model);

Result:

Undefined property: stdClass::$teacher_model

Why???


Solution

  • All of this was executed trough a function. I just discovered that my $fields object was created before being populated and my function, so will my var_dump was executed many times, even if I only see last recursion, I can see result of var_dump($fields), just because all previous recursions of var_dump not trigger any error. So for object property accessibility, in Laravel/October CMS, sometimes you have to do this under conditions. I put this before and it works perfectly.

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