How to improve:
class gotClass {
protected $field1;
protected $Field2;
protected $field3;
(...)
function __construct($arg1, $arg2, $arg3, $arg4) {
$this->field1 = $arg1;
$this->field2 = $arg2;
$this->field3 = $arg3;
(...)
}
}
to something nice and compact like
function __construct($args) {
$className = get_called_class();
$classAttributes = get_class_vars($className);
foreach ($args as $arg -> $value)
if (array_key_exists($arg, $classAttributes))
$this->$arg = $value;
}
I can't get it work, I don't know the right functions to use. Did I mention I'm new to PHP? Your help is much much appreciated.
protected
fields when you construct. – jon_darkstar Apr 9 '11 at 21:46