Many of the tutorials I've watched about PHP OOP use getter and setter methods to set invidivual properties and retrieve data from an object. But I'm wondering if the second approach of passing all properties in an array is okay and if not, why?
$obj = new MyClass();
OPTION 1: Setter & Getter
$obj->setKeyword("orange");
$obj->setTitle("Title Name");
$obj->setPage(4);
$obj->setContent("Blah blah blah");
$obj->setTemplate("template.tpl");
$disp = $obj->getContent();
OPTION 2: Array & Getter
$params = array('keyword' => "orange",
'title' => "Title Name",
'page' => 4,
'content' => "Blah blah blah",
'template' => "template.tpl"
);
$obj->setParams($params);
$disp = $obj->getContent();
I'm leaning toward OPTION 2 for a script I'm writing because there are about two dozen properties that can potentially be set for the object, and I feel that maybe just sending them all in an array is the easiest way to do it. I also don't need to create a get and set method for every property, which I think would cut down on the amount of code I need to create for the class.
Is there anything wrong with Option 2? Is it better to use getter and setter methods as shown in Option 1? Thanks!