PHP Function Arguments: Array of Objects of a Specific Class

后端 未结 4 1766
走了就别回头了
走了就别回头了 2020-12-17 14:49

I have a function that takes a member of a particular class:

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

I\'d like to make another

4条回答
  •  情书的邮戳
    2020-12-17 15:33

    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)
    

提交回复
热议问题