diff --git a/src/Model/ViewModel.php b/src/Model/ViewModel.php index 7ad0f1d7..6078feb7 100644 --- a/src/Model/ViewModel.php +++ b/src/Model/ViewModel.php @@ -262,7 +262,7 @@ public function setVariables($variables, $overwrite = false) } if ($overwrite) { - if (!is_object($variables) && !$variables instanceof ArrayAccess && !is_array($variables)) { + if (is_object($variables) && !$variables instanceof ArrayAccess) { $variables = ArrayUtils::iteratorToArray($variables); } diff --git a/test/Model/TestAsset/Variable.php b/test/Model/TestAsset/Variable.php new file mode 100644 index 00000000..f1569105 --- /dev/null +++ b/test/Model/TestAsset/Variable.php @@ -0,0 +1,36 @@ +assertSame(iterator_to_array($options), $model->getOptions()); } + public function testAllowsPassingNonArrayAccessObjectsAsArrayInConstructor() + { + $vars = array('foo' => new Variable); + $model = new ViewModel($vars); + $this->assertSame($vars, $model->getVariables()); + } + public function testCanSetVariablesSingly() { $model = new ViewModel(array('foo' => 'bar'));