开发者

Properties v method variables

new PHP OOA and have two related questions:

class foo {
    pri开发者_开发知识库vate $string = null;
    private $some_trivial_flag = false;

    1)public function help_doing_some_stuff() {

    2)*public function help_doing_some_stuff($some_trivial_flag)* {

         if(!$this->some_trivial_flag(..) ...
    }

public function do_some_stuff() {
    1)  $this->help_doing_trivial_stuff(); 
    2)  *$this->help_doing_trivial_stuff$($this->some_trivial_flag);*    
    }
}

or

class foo {
   private $string = null;

   public function help_doing_some_stuff($some_trivial_flag) {
      if(!$this->some_trivial_flag(..) ...
   }

  public function do_some_stuff() {
     $some_trivial_flag = false;
     $this->help_doing_trivial_stuff($some_trivial_flag);
  }

Is it best to declare every variable used inside a class as a property or keep some declared in the class methods. Also if you have declared it as a property should you still list in the the methods parameter list?


Declare as member variables those variables whose state you need to retain between member function calls.

That's it.

The choice of what variables you accept as parameters to functions is completely unrelated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜