douyou8047 2016-09-12 07:01
浏览 35

函数($ param)添加到函数__construct

I have two functions in a class:

        public function __construct()
        {
          $this->page=$this->Pagination_page();
        }

        function Pagination_page($page){     
          return $page;
        }

This version is not working. How can I add to the $this->page the Pagination_Page value?

  • 写回答

2条回答 默认 最新

  • douzhi7082 2016-09-12 07:08
    关注

    It's not working because the constructor is initialized when you instanciate the object - it's 0 there. But you cannot assign this value of $page at the start you must call the method first. If you want to do this you should create it in the construct directly:

    public function __construct($_page)
        {
          $this->page=$_page;
        }
    

    If you want to use the "thing" you created then:

    public function __construct($_page)
        {
          $this->page=$this->Pagination_page($_page);
        }
           function Pagination_page($page){     
               return $page;
        }
    
    评论

报告相同问题?