Things are not that easy, since there is no way for php to somehow magically guess what to do with the values of that array. Objects are a structured set of data unlike an array. So you need a description of the structure and rules how to use it.
You need to implement a constructor in the class definition, then you can construct a new object based on some given array. Take a look at this arbitrary example:
<?php
class A {
protected $title;
protected $data;
public function __construct ($data) {
$this->title = $data['title'];
$this->data = sprintf('this is foo: %s', $data['foo']);
}
public function __toString() {
return sprintf(
"I am an object titled '%s'\nI hold that foo value: %s\n",
$this->title,
$this->data
);
}
}
$data = [
'title' => 'hello world',
'foo' => 'foovalue',
'bar' => 'barvalue'
];
$object = new A($data);
echo $object;
var_dump($object);
The obvious output is:
I am an object titled 'hello world'
I hold that foo value: this is foo: foovalue
/home/arkascha/test.php:25:
class A#1 (2) {
protected $title =>
string(11) "hello world"
protected $data =>
string(21) "this is foo: foovalue"
}