Is it possible to create a PHP class that can hold whatever type of data you throw at it, even recursively, using magic methods?
I saw this: PHP - Indirect modification of overloaded property
but it doesn't handle recursive data:
class ActiveRecord extends Creator {
}
$a = new ActiveRecord();
$a->_id = "123456789";
$a->persona_info = [
"name" => "Bob",
"surnames" => ["First", "Second", "Third"]
];
$a->history = [
"logins" => [
[
"date" => "1999",
"ip" => "1.2.3.4"
],
[
"date" => "1129",
"ip" => "1.2.3.4"
]
],
"purchases" => [
[
"date" => "1819",
"amount" => "1884"
],
[
"date" => "1459",
"amount" => "14"
]
]
];
var_dump($a->history->logins);
That gives me:
PHP Notice: Trying to get property of non-object in /tmp/x.php on line 90
PHP Stack trace:
PHP 1. {main}() /tmp/x.php:0
NULL
Trying to investigate further, I see that $a->history
is a plain php array instead of a Value
object (or even a Creator
object.