PHP Function Arguments: Array of Objects of a Specific Class

No, it's not possible to do directly. You might try this "clever" trick instead:

public function addPages(array $pages)
{
    foreach($pages as $page) addPage($page);
}

public function addPage(My_Page $page)
{
    //
}

But I 'm not sure if it's worth all the trouble. It would be a good approach if addPage is useful on its own.


Instead of passing an array of objects (array(My_Page)), define your own class and require an instance of it in your function:

class MyPages { ... }

public function addPages(MyPages pages)

You can also add PhpDoc comment to get autocomplete in IDE

    /**
     * @param My_Page[] $pages
     */
    public function addPages(array $pages)
    {
      // ...
    }