Assignment of class variables by php
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. if the change quantity does not belong to this class, throw an 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 values? Obviously, I have defined $ pagebarnum in the class. is it necessary for me to assign values using set?
Reply to discussion (solution)
Variable initialization and adjustment are of course necessary. Suppose you need 10 parameters for a page and 5 parameters for a page. are you doing two classes?
Variable initialization and adjustment are of course necessary. Suppose you need 10 parameters for a page and 5 parameters for a page. are you doing two classes?
If you instantiate a class and pass the parameter in, you can directly use $ this-> pagebarnum = $ array ['page _ name']. what is the difference between checking the existence of variables in the set method? Pagebarnum has defined the meaning of checking 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 values to non-existent pagebarnum attributes, while the former creates a public pagebarnum attribute for non-existent attributes pagebarnum.