Читать книгу PHP This! A Beginners Guide to Learning Object Oriented PHP - Michelle Gosney - Страница 7

$this Variable

Оглавление

The $this variable is a pointer to the object making the function call. That may not mean much to you so let’s explain it as it applies to Mindi. In the movie “Weird Science” two geeks created a metaphysical hot chic. That’s what we did when we instantiated $Mindi. Her blueprint was the Person class. We gave her dazzling blue eyes with the following method:


That method is defined in the Person class like so:


So $this was replaces with $Mindi at the moment $Mindi was instantiated because $Mindi is a copy of the Person class except with specific attributes instead of generic ones like $this. Hence the $Mindi object sees the setEyeColor(‘blue’) method like this:


PHP This! A Beginners Guide to Learning Object Oriented  PHP

Подняться наверх