I have seen something like this in an ORM:
$b = new Book();
$b->limit(5)->get();
echo 'ID: ' . $b->id . '<br />';
echo 'Name: ' . $b->title . '<br />';
echo 'Description: ' . $b->description . '<br />';
echo 'Year: ' . $b->year . '<br />';
foreach ($b as $book)
{
echo 'ID: ' . $book->id . '<br />';
echo 'Name: ' . $book->title . '<br />';
echo 'Description: ' . $book->description . '<br />';
echo 'Year: ' . $book->year . '<br />';
echo '<br />';
}
How is it possible that an object acts as both array and object? How can I accomplish that? I was hoping to see a new __magic method or something in Book's parent class, but I couldn't find anything, so there might be something really basic about php objects that I don't know.
Any thoughts? Thanks in advance