11.
The Constructor!
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.
16 Comments
I wonder if it would be possible that some tutorials around OOP design patterns could be considered (angled at PHP)? There is lots on the web, but most of it is written in hard to understand language with very poor examples. It would be awesome to have something written in KNP-speak that everyone can understand. Just an idea. :)
Ah, that's very nice! I agree - it's a really solid idea, especially as we keep developing the OO track. We have a tracker for course ideas - I've just added your comment to it.
Thanks!
How can I check what exactly has been updated?
Hey Krzysztof! Do you mean what has been updated on the tutorial - because you're seeing the new "updated" label on some tutorials?
Yes :)
We don't have any specific details on *what's* been updated on a tutorial yet - but I've added that to our issue tracker (I'd like to show a log of what was updated and when). In this case, we made some minor changes to the course description - so nothing too interesting :).
Hey guys!
I'm just wondering where does '$_GET['error']' come from in the index.php?
Hey György C.!
Fair question! Check out the
battle.phpfile - you'll see it there. Basically, if a form is POST'ed to battle.php and the form is missing some data, we redirect back to /index.php?error= with the error code. We built this out in our PHP intro course (but didn't explain it here). Let me know if I an offer more explanation.Cheers!
Hey weaverryan !
I see the code in battle.php, thanks.
Do you have a course in that you build up this project from the ground up to the point where the oop part begins?
I've only found the projet for "pet's listing website".
Anyway, I really appriciate all the work you are doing on 'symphonycasts'.
Best!
Hey György C. !
Yea know what? I was totally wrong (bad memory!). This is the *first* course where we use this code: so there is no course where we build this app from scratch. Sorry about that! The PHP track - https://symfonycasts.com/tr... - builds a different project, but that's where we cover the concepts in the "starting" code for this course.
If you have any questions about the code along the way (like you already asked), we'd be happy to do our best to answer them :).
Cheers!
Hi there. Is it ever likely that the Ship properties are going to be 0? When would it be more beneficial to use setters for these properties rather than via the constructor? It would seem you can do both so there must be some underlying principal as to when to choose either approach?
Thank you :)
Hey ThingyBob,
Usually, if some object properties are required to be set - you can make it setting in the constructor. Because, if you do not pass required arguments into constructor - the object won't be created and you'll get a fatal error. But if some properties are optional during instantiating the object - you may use setters to be able to set them later if necessary. Basically, you can think of it this way. So, if you want sure that some fields are set during object creating - do it in its constructor. of other properties that you need to set after object was created, e.g. during its modification - sue setters.
And we set some properties to 0 just to give some reasonable defaults. We just want to make sure that those properties are "numbers" not "null".
I hope it makes sense to you.
Cheers!
Hi there,
I would like to know how you get these nice formatted var_dump output.
When I use var_dump($somevariable); die; and view it in firefox or chrome I get unstyled stuff in one long single line.
Hey harm2o,
Good questions! :) Yeah, it's a special PHP extension called Xdebug - you can install it and your output will be similar the same as ours. Or, you can look into a Symfony component called VarDumper: https://symfony.com/doc/cur... - but you can use it outside of Symfony projects as well, it just has a nice integration with Symfony web developer toolbar.
Cheers!
Hi Victor,
thanks for your reply. I installed xdebug.
Now I get these nice colorful messages :)
Hey Harm2o,
Awesome! It has a lot of good things.. but take a look at the Symfony's VarDumper as well, it really nice and helps even better in Symfony apps ;)
Cheers!
"Houston: no signs of life"
Start the conversation!