php什么时候使用数组作为参数/属性

For the following two classes:

should I use array as a parameter or one by one?

class image {

    public function __construct(array $color, array $padding) {
        ...
    }
}

class image {

    public function __construct($red, $green, $blue, $paddingtop, $paddingright, $paddingbottom, $paddingleft) {
        ...
    }
}

Also for class properties:

class image {
    protected $paddingtop;

    protected $paddingright;

    protected $paddingbottom;

    protected $paddingleft;

    protected $colorred;

    protected $colorgreen;

    protected $colorblue;
}

class image {

    protected $padding = array('top' => ..., 'right' => ..., 'bottom' => ..., 'left' => ...);

    protected $color = array('red' => ..., 'green' => ..., 'blue' => ...);

}

Is it better to treat them as an array or a single variable?

Maybe this question don't have a fixed answer, but I'm just a php beginner and don't have any work experience, I wanna hear your suggestion which way is the most common use or easy for other coders to read.

Thanks!

You don't ever want that many arguments to a function... You could use an options array(s) or you could just use setter methods to set the properties. I have a hard time believing all of those would be required to create an object instance.

As far as class properties that depends on the nature of their use. Generally speaking seperate properties are better because it makes for an easier to read interface and helps with IDE code hinting. But in this case, especially the padding, i think it would make more sense to use the array like you have in your second example.

This would be completely subjective; however, I will throw my two cents in to the conversation. My rule of thumb is if there are more than 4 parameters than try to bundle them arrays if they make sense together. So, the example's padding and colors go together well as arrays.

Also, try to make the arrays in a fashion that the user does not have to worry about which index each element is in, such as using an associative array.