PHP Function Arguments: Array of Objects of a Specific Class

后端 未结 4 1742
走了就别回头了
走了就别回头了 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:18

    if you use the class, you can do some thing like this:

    interface addPageInterface
    {
       public function someThing();
    }
    
    
    class page implements addPageInterface
    {
       public function someThing()
       {
          //for example: create a page
       }
    }
    
    
    class addPage
    {
       public function __construct(addPageInterface $page)
       {
           //do some thing...
    
          return $page; //this will return just one page
       }
    }
    
    
    class addPages
    {
       public function __construct(addPageInterface... $page)
       {
          //do some thing...
    
          return $page; //this will return an array which contains of page
       }
    }
    

提交回复
热议问题