I have a php object method that load object "A" with the following MySQL query:
SELECT A.foo, A.bar...
I have another php object named B that uses MySQL fields from object A:
SELECT A.foo, A.bar...
B.abc, B.xyz
To prevent code repetition, would it be considered a good practice to create an array (or an object) that stores the MySQL fields names of Object A so that this array can be used in object A and object B, like this:
Object A MySQL loading:
SELECT '.implode(',', $mysql_a_fields).' '...
Object B MySQL loading:
SELECT '.implode(',', $mysql_a_fields).',
B.abc, B.xyz
Or would it be code smell?
The goal is to to prevent repeating some SQL fields along queries that use those SQL fields. For example, if there is a mysql date field for object A that I want to get formatted the same way in all the requests I use this date field, is there any design pattern to prevent repeating DATE_FORMAT(date_field) in all the request?
Thank you