Accessing Methods1:57 with Alena Holligan
We can access the methods similar to the way that we access normal functions and the object properties. The only difference is that we first reference the object it belongs to, just like we did when accessing a property.
To use the displayRecipe method, we call it just like a regular function. The only difference is that we first reference the object it belongs to, with the object-operator (->), just like we did when accessing a property.
First let's clean up our display. 0:00 Now to use the display recipe method, we call it just like a regular function. 0:10 The only difference is that we first need to reference the object it belongs to. 0:20 We do this just like we access the property, the name of the object, 0:28 followed by the dash in the greater than, which make up the single arrow. 0:33 We can then use echo to display this method to the screen. 0:37 Before we run the script, we haven't set our titles for our recipes yet. 0:42 So let's do that. 0:46 Now let's display both recipes, 1:13 And run our script again. 1:23 In the console we see. 1:28 My first recipe by Grandma Holligan. 1:30 My second recipe by Betty Crocker. 1:33 In this section we've completed our first jaunt into the world 1:36 of object oriented php.. 1:40 By learning about classes, properties, methods, and objects. 1:41 We've just scratched the surface of what we can do. 1:46 So let's keep exploring our new paradigm 1:49 by building out some of the actual recipes and learning some magic along the way. 1:52
You need to sign up for Treehouse in order to download course files.Sign up