Which is the better approach to initialize php properties?

前端 未结 5 1587
眼角桃花
眼角桃花 2021-02-19 11:35

Here are two way to initialize class variables.

1st Method

class Test {
    private $var1;
    private $var2;

    public function Test($var1,$var1) {
         


        
5条回答
  •  既然无缘
    2021-02-19 12:21

    If those variables are necessary for the operation of the class, you would beter use the first method. That way you can ensure they are set when the class is created.

提交回复
热议问题