We have one table meta where there is key and value so each of the row represents one component or service and then we have api system which manages the metas database. And it was going pretty well when we had 10 rows = 10 properties now it grew to be 30 and its so annoying i am using php and lets say it looks like

Class metas {
private $metas1=[]
private $metas2=[]
private $metas3=[]

Now i think the best way to manage this class is to put these keys on yml file but is it the best way?

  • 1
    You have implemented something known as EAV. Take a look at the link because Wikipedia also introduce alternatives, like turning this model into mere jsons (some SQL DB supports specific types for json)
    – Laiv
    Mar 28, 2018 at 18:15
  • Using a proper config file (like YML, or TOML, or even .ini) seems reasonable. This is clearly data, it should not mix with code proper.
    – 9000
    Mar 27, 2019 at 13:38
  • 1
    What is annoying?
    – NoChance
    Mar 27, 2019 at 14:40

1 Answer 1


Whenever you start numbering your properties, such as:

private int myField1;
private int myField2;
private int myField3;

What you're really doing here is trying to hardcode a list, and you should be using a collection type instead (whether an array, list, or any other collection type is contextual and language dependent):

private int[] myFields;

This example uses int as the base type, but that is not the case for you.

I suspect this is PHP (due to the $)? Your example is a bit light on the specific ypes being used, and I'm no PHP dev, but it seems to me that your individual fields are already some sort of collection type (due to the []), so the type of your "list of fields" property will be something along the line of an array of arrays, also known as a multi-dimensional array

The example code on the page I linked seems to match your goal of a key/value dictionary:

$cars = array (
  array("Land Rover",17,15)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.