Reputation: 3424
Any time I want to use an instance variable, I need to use the pseudovariable $this, am I correct? And if those are objects with methods, I'm still having to use them. So when I have an example like so:
class myClass{
private $thingOne;
private $thingTwo;
public function __construct($thingOne,$thingTwo){
$this->thingOne = $thingOne;
$this->thingTwo = $thingTwo;
}
}
And then I start adding methods to myClass
I have to start typing things like:
$this->thingOne->doSomething($this->thingTwo->doSomethingElse());
But I would much rather type:
$thingOne->doSomething($thingTwo->doSomethingElse());
I just find writing this-> all the time to be annoying. Can't it just be assumed that I'm using the instance variables that I have given it? My code ends up having this this this this this this this everywhere.
Could I rename it to something shorter? $t or something?
Upvotes: 0
Views: 87
Reputation: 4680
$this
is a reference to the current class object and cannot be renamed. You could make your own reference variable, but you would have to declare it in every method, thus making it inefficient. Instead you should just regularly use $this
.
Upvotes: 1