Phalcon/Config offset not set.

I'm iterating over a Config object, during the iteration I take a copy of that config object and go play with that (I unset the 'widget' property of that copy).

On second loop over the config object I try to access the 'widget' property and I get a Undefined Offset error.

The following code snippet basically shows my quandry

foreach ($block as $options) {
       var_dump($options);
       $newOptions = $options;
       $widget = $newOptions->widget;
}

Output

object(Phalcon\Config)#143 (4) {
    ["widget"]=>
    string(11) "ContentList"
    ["type"]=>
    string(4) "test"
    ["apply_filter"]=>
    bool(true)
    ["filter"]=>
    object(Phalcon\Config)#2946 (1) {
      ["title"]=>
      object(Phalcon\Config)#854 (1) {
        ["$regex"]=>
        string(8) "^Title O"
      }
    }
  }

Followed by the error. Before I write a bug report, is there something I'm missing about the way this should work?



83.4k
edited Aug '14

I'm running the following code:

<?php

$block = new Phalcon\Config(array(
        'options' => array(
                'widget' => 'ContentList',
                'type'   => 'test'
        )
));

foreach ($block as $options) {
        var_dump($options);
        $newOptions = $options;
        $widget = $newOptions->widget;
        var_dump($widget);
}

And it's showing:

object(Phalcon\Config)#2 (2) {
  ["widget"]=>
  string(11) "ContentList"
  ["type"]=>
  string(4) "test"
}
string(11) "ContentList"

Could you please update the issue to show the problem up?

$block = new Phalcon\Config(array( 'options' => array( 'widget' => 'ContentList', 'type' => 'test' ) ));

    foreach ($block as $options) {
        if (isset($options->widget)) {
            unset($options->widget);
        }

    }

    foreach ($block as $options) {
        print_r($options);
    }

Normal looping behaviour wouldn't affect the parent object or array when unsetting a property/key as far as I know. But here on the second loop $options has been changed.

    Phalcon\Config Object ( [type] => test )