> That said, I generally use arrays rather than DTO objects

I too have often used arrays. But then I have always been rigorous to ensure 
that variables and array elements are initialized before use, and fortunately I 
do not have a lot of typos in code I write.

However I recently took on a large PHP app to refactor where the previous 
developers had used arrays profusely with very little pre-initialization.  So I 
started to add in all initialization and checking to be certain variables had 
been initialized and realized it was an overwhelming task. 

I changed course and am now replacing all all arrays that are emulating a 
struct (vs a collection) to instances of declared classes and it has made a 
major improvement in my ability to refactor without bloating the code to 2-3x 
the original size. I has also allowed me to consolidate lots of repeated code 
in one place in  methods and constructors.

Given that experience and knowing that using "args" for optional parameters 
means my function signatures are much less likely to change, it would be super 
helpful if I could do so with type-checked object initializers instead of array 
literals.

-Mike

Reply via email to