Reputation: 15950
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.
Upvotes: 0
Views: 115
Reputation: 92316
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
.
Upvotes: 1