Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Accessing Methods1:57 with Alena Holligan
We can access the methods similar to the way that we access
Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
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.
Now to use the display recipe method, we call it just like a regular function.
The only difference is that we first need to reference the object it belongs to.
We do this just like we access the property, the name of the object,
followed by the dash in the greater than, which make up the single arrow.
We can then use echo to display this method to the screen.
Before we run the script, we haven't set our titles for our recipes yet.
So let's do that.
Now let's display both recipes,
And run our script again.
In the console we see.
My first recipe by Grandma Holligan.
My second recipe by Betty Crocker.
In this section we've completed our first jaunt into the world
of object oriented php..
By learning about classes, properties, methods, and objects.
We've just scratched the surface of what we can do.
So let's keep exploring our new paradigm
by building out some of the actual recipes and learning some magic along the way.
You need to sign up for Treehouse in order to download course files.Sign up