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

Instantiation

Оглавление

Let’s start with the term “instantiate.” To instantiate a class means to create an object based on that class, or to create an instance of that class. In PHP the way to do this is by using the new keyword like this:


$Mindi and $Billy are now both instances (objects) of the class Person so their properties can be assigned specific values. Notice how I used the parenthesis after Person. This is because of the constructor I defined in the Person class, the first function just after the properties are defined. This constructor is not implemented in this example and I will explain this in detail in Chapter 3 when I discuss Magic Methods.

Let’s start with Mindi. We all know about her tattoo but let’s officially set her name and gender and some other attributes:


Now for Billy:


PHP This! A Beginners Guide to Learning Object Oriented  PHP

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