zendframework / zend-stdlib

Stdlib component from Zend Framework
BSD 3-Clause "New" or "Revised" License
384 stars 76 forks source link

Allow define order of options in AbstractOptions #57

Closed marc-mabe closed 8 years ago

marc-mabe commented 8 years ago

In some cases the order of options passed as array in AbstractOptions::setFromArray() is important.

E.g. An option 'host' differs by option resource_id, than the following two snippets produce a different result and produces WTF moments.

$options = new MyOptions([
    'host' => 'example.com',
    'resource_id' => 'example',
]);
$options = new MyOptions([
    'resource_id' => 'example',
    'host' => 'example.com',
]);

For more information read here: zendframework/zf2#6381

zf2timo commented 8 years ago

Please submit a PR with a Unit Test that covers the expected behavior.

As i see it the AbstractOptions::setFromArray only call magic __set Method - which try to execute a Setter of MyOptions.

weierophinney commented 8 years ago

@marc-mabe I'd consider this to be something the concrete implementations should do, not the abstract class.

The abstract class is written to cover the majority of use cases. Extensions can handle this aspect. If order of operations is required, then the implementation should override setFromArray() to enforce the order.