PHP assigns a class variable to a value problem

Source: Internet
Author: User
Private $pagebarnum =10; $this->pagebarnum  = $array [' page_name ']; $this->set (' Pagebarnum ', $array [' Page_ Name ']);/**     * Sets the value of the variable name specified in the class, and if the amount of change does not belong to this class, throw a exception     * @param unknown $var     * @param unknown $value     */    function set ($var, $value) {        if (In_array ($var, Get_object_vars ($this))) {            $this, $var = $value ;        } else{            $this->error (__function__, $var. "Does not belong to pb_page!");        }    }

$this->pagebarnum = $array [' page_name ']; and $this->set (' Pagebarnum ', $array [' page_name ']); What is the difference between assignments, clearly I have defined the $pagebarnum in the class, I use set to assign value and this is necessary?


Reply to discussion (solution)

Variable initialization and adjustment of course it is necessary to assume that you need a page parameter is 10, a page parameter is 5, you do two classes?

Variable initialization and adjustment of course it is necessary to assume that you need a page parameter is 10, a page parameter is 5, you do two classes?


Instantiating a class to pass in can be achieved, but what is not understood is directly with $this->pagebarnum = $array [' page_name ']; and the Set method first check the existence of the variable is not what is the difference? Pagebarnum has been defined to check what it means when I create a class.

$this->pagebarnum = $array [' page_name '];
$this->set (' Pagebarnum ', $array [' page_name ']);
The difference is that the latter does not assign a value to a nonexistent property pagebarnum, which creates a public Pagebarnum property pagebarnum the non-existent property

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.