0

I am designing an OOP application, it's my first application.

I have class (similar to one mentioned below)

class Temp {
      private function a() {

          <code goes here>
      }

      private function b() {

          // To call method 'a', I am using $this
          $this->a();
          // Is it correct?
      }
}

I don't know whether I should call another private method from a private method using $this.

Am I doing correct in above example?

Thanks.

I-M-JM
  • 15,732
  • 26
  • 77
  • 103

3 Answers3

2

Looks perfectly fine to me - well done.

Marty
  • 39,033
  • 19
  • 93
  • 162
1

Yes, this is correct. Private means that it is meant to be used only within the class that defines it, but not in derived classes. So in your case, you can call a and b anywhere within your Temp class. But if you derive another class from it, say SubTemp, you may not call a or b within the implementation of SubTemp.

DarkDust
  • 90,870
  • 19
  • 190
  • 224
0

Yes, you are doing it in correct way.

Gaurav
  • 28,447
  • 8
  • 50
  • 80