08.
Using Objects
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
8 Comments
Why not put the printShipSummary() into the object also?
Hi Oscar!
Yea, you could totally do this - I don't see any reason *not* to based on how things are setup now. Later, in part 2 (http://knpuniversity.com/sc..., we'll talk about "service classes". The printShipSummary() might also be perfect for a service class. But either way: yes - I would eventually make *all* flat functions into object methods.
Cheers!
Nice tut. Good to go over some of the basics again. Anyway I noticed that Chrome shows a nice output for you when viewing your outputted objects such as this: http://imgur.com/a/HNbA4 However on my PC it looks like this: http://imgur.com/a/k3tTE Are you using a plugin for this styling?
Hey John,
Thanks! That's not a Chrome plugin but PHP extension which is called Xdebug. For Linux servers it's easy to install with
$ sudo apt-get install php5-xdebug. BTW, there's another nice solution for dumping variables: <a href="http://symfony.com/doc/current/components/var_dumper.html">Symfony VarDumper Component</a>. It just a simple library you can easy install with Composer, but has even cooler output than xdebug, be sure to look at it ;)Cheers!
On Chapter 8, you tell us to "copy" the ship class...
I think you mean MOVE the ship class to the new file...
You don't want two versions of the same class - right?
Hey T. Wagner,
Ah, yes, technically you're right! We cut the class from play.php and put it into the Ship.php. We're sorry for misleading you a bit here, but yes, the Ship class is meant to moved to the new file instead of being copied. Unfortunately, we said "copy" in the video, and we do want our scripts match the scripts. Btw, did you watch the video or just read the scripts? Because on the video it's clear that we actually cut and paste instead of copy and paste.
Cheers!
PHPStorm gets angry. Can I get auto-completion for $ship->getNameandSpecs() in the foreach loop aswell?
Just hanging around and watch some basic PHP stuff
Great work :)
Update: Ok, ok I got it. In functions php we can write:
Hey Chris,
You're totally correct! Glad you found the solution by yourself ;)
Cheers!
"Houston: no signs of life"
Start the conversation!