Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Class and Method Interaction1:26 with Hampton Paulk
Class and Method Interaction
I want to provide you with two very helpful ways
that PHP will allow you to interact classes and methods.
The first is using variables to pass
through your class and method names programmatically.
First lets create a variable named the same as one of our classes,
so lets do a variable dollar sign class and set it equal to product.
Now instead of using product for a new product,
we can simply say dollar sign p equals new class.
This way we can substitute variables for our actual class names.
Another nice trick is with method calls from string variables.
Here we create a variable with the same name as one of our methods.
Say for instance, dollar sign m, and we set that variable equal to getName.
Then you can substitute that variable with your
method name when calling it on an object.
So dollar sign name is equal to dollar sign p, which is
our product object that we created above on line three, and then
make a method call using the object operator to our variable m,
but in this case we don't use the dollar sign, just m.
There are many more examples about method interaction available on the PHP.net site.
These are just a couple of my favorites.
You need to sign up for Treehouse in order to download course files.Sign up