Bir dizi gibi davranan nesne?

0 Cevap php

Ben bir ORM böyle bir şey gördük:

    $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.

Herhangi bir düşünce? Şimdiden teşekkürler

0 Cevap