PHP - Initialize object members with array parameter
Is it possible to initialize an objects private or protected members in php with an associative array. for example: class TestClass { public $_name; public $_age; public function __construct(array $params) { ?????? } } $testClass = new TestClass( array( 'name' => 'Bob', 'age' => '29', ) ); i was wondering whether there is an elegant solution - perhaps by implementing one the spl interfaces or otherwise? You mentioned SPL. But without knowing the exact requirements for the purpose of your object, the below is about the only information I can give... You could have your object extend the SPL