General discussion

Store class options: in properties on in Options class (php)

By mrself ·
A long time I had a constructor which took outer options / dependencies and set them to local properties. However soon I started to use Symfony OptionsResolver. So my constructor takes only one array with options / dependencies, they were passed to OptionsResolver and set in local property "options". So I got an options with this: "$this->options['myOption']". Then I found than using a simple array for options has some disadvantages (like no type hinting) and decided to make "options" property an instance of "Options" class. So then I had "$this->options->myOption". However afterwards I thought over my approach and it seemed to me that most people do not use Options class of an array for getting options. They set them in the main class as properties like this "$this->myOption". So now I am stuck at the decision how to organize options. On one hand options are outer data and there is no need to save them as properties and it's better to create a separate object for them (like DTO). But on another hand Options class is like a bridge and I am thinking do I need to separate Options class from my main class.

I need quotes from experienced people who will understand my problem, have enough knowledge to help me resolve this issue.
0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Back to Web Development Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums