I downloaded the source code and noticed there was some inconsistency in the code displayed in the battle.php file. From what I can tell, the inconsistency is caused by:
a CRLF is after line 4
the instance of BattleManager is before the 'if' statement for the 'bad_quantities'
About the CRLF - that's very minor and you can totally ignore it. About the instance of BattleManager is before the 'if' statement for the 'bad_quantities' - yeah, a little misplace for that line in the code vs what we show in the video, but very minor too. If we're talking about the performance - you definitely want to have that line after the if to exit earlier without creating the instance. But for learning purposes it's not that much important and work both ways. But good catch!
this keeps confusing me, where exactly do I get the databse from? I've tried setting it up but even changing user and pass I don't have permissions. How do I set up permissions? Am I suppose to install something?
I had MySql installed and tried adding the database, and I still keep getting Error: [28000][1045] Access denied for user How do I add perissions for user or check user permissions? I tried llooking in MySQL documentation but can't find it. When I try using mysql --help I get command not found, but I know it is installed as I use it in another repository
You can try to login to your mysql server with mysql binary or with phpmyadmin if you configured it, if you are using mysql directly you can create user for the DB with following queries:
CREATE USER '<USERNAME>'@'localhost' IDENTIFIED BY '<PASSWORD>';
GRANT ALL PRIVILEGES ON <DB_NAME>.* To '<USERNAME>'@'localhost';
FLUSH PRIVILEGES;
be sure to set correct <USERNAME> and <PASSWORD> with the <DB_NAME>
Just wondering do i need to download the course code or can i use the code from OO course 3 as we have left. Or are there things in this course code that i need to have in order to follow this code.
We recommend to download course code for each tutorial and work in start/ directory. The reason behind it is that most of the time we do minor changes and improvements after previous courses, like upgrading dependencies to the new latest versions, add more code examples, slightly tweak or add new code. Most of them are minor, but if you want to exactly match the video - better to start with new downloaded code. But it's not a requirement! You can still continue your project applying new changes to it. You even can commit with Git all your changes you have before start the new course, then download new course code, and copy the code from the start/ directory to your project and with "git diff" command you'll review any changes that were made by us. So, you can either leave or discard them. This is always a good strategy to continue your project but keep up to date with our changes at the same time.
Hey! In the exercise I just tried $this::CONST instead of ClassName::CONST within the class method. It seemed to work, but is it a sensible thing to do? Thank you!
You found the flexibility of PHP! This does work... but I wouldn't do it on purpose :) - mostly because it is kind of "unexpected" (like, wait, why is he/she doing that? Is something fancy happening here!?). The key thing is that constants are *static* - they're a "thing" that's attached to the *class* (e.g. ClassName) itself - it is not something that's attached to your object. When you use $this::CONST (you can also have $someObj::CONST) it makes it kind of look like the constant is somehow attached to the object instead of the class.
But, I like that you're poking at things to see if they work - all good for learning :).
13 Comments
I downloaded the source code and noticed there was some inconsistency in the code displayed in the battle.php file. From what I can tell, the inconsistency is caused by:
Hope that helps anyone.
Hey JDCrain,
Thank you for the head ups!
About the CRLF - that's very minor and you can totally ignore it. About the instance of BattleManager is before the 'if' statement for the 'bad_quantities' - yeah, a little misplace for that line in the code vs what we show in the video, but very minor too. If we're talking about the performance - you definitely want to have that line after the if to exit earlier without creating the instance. But for learning purposes it's not that much important and work both ways. But good catch!
Cheers!
this keeps confusing me, where exactly do I get the databse from? I've tried setting it up but even changing user and pass I don't have permissions. How do I set up permissions? Am I suppose to install something?
Hey @Didi
Yep, you should have MySQL server installed.
Cheers!
I had MySql installed and tried adding the database, and I still keep getting
Error: [28000][1045] Access denied for userHow do I add perissions for user or check user permissions? I tried llooking in MySQL documentation but can't find it. When I try using
mysql --helpI get command not found, but I know it is installed as I use it in another repositoryhey @Didi
You can try to login to your mysql server with
mysqlbinary or with phpmyadmin if you configured it, if you are using mysql directly you can create user for the DB with following queries:be sure to set correct
<USERNAME>and<PASSWORD>with the<DB_NAME>Cheers!
Hi!
Just wondering do i need to download the course code or can i use the code from OO course 3 as we have left. Or are there things in this course code that i need to have in order to follow this code.
Cheers!
Hey Emin,
We recommend to download course code for each tutorial and work in start/ directory. The reason behind it is that most of the time we do minor changes and improvements after previous courses, like upgrading dependencies to the new latest versions, add more code examples, slightly tweak or add new code. Most of them are minor, but if you want to exactly match the video - better to start with new downloaded code. But it's not a requirement! You can still continue your project applying new changes to it. You even can commit with Git all your changes you have before start the new course, then download new course code, and copy the code from the start/ directory to your project and with "git diff" command you'll review any changes that were made by us. So, you can either leave or discard them. This is always a good strategy to continue your project but keep up to date with our changes at the same time.
I hope this helps
Cheers!
Hey!
In the exercise I just tried $this::CONST instead of ClassName::CONST within the class method. It seemed to work, but is it a sensible thing to do? Thank you!
Yo Max!
You found the flexibility of PHP! This does work... but I wouldn't do it on purpose :) - mostly because it is kind of "unexpected" (like, wait, why is he/she doing that? Is something fancy happening here!?). The key thing is that constants are *static* - they're a "thing" that's attached to the *class* (e.g. ClassName) itself - it is not something that's attached to your object. When you use $this::CONST (you can also have $someObj::CONST) it makes it kind of look like the constant is somehow attached to the object instead of the class.
But, I like that you're poking at things to see if they work - all good for learning :).
Cheers!
I can just add that there are two additional ways to get the value of a constant inside of a class:
- self::CONST
- static::CONST
PHP is indeed very flexible! :)
Hey Serge,
Yeah, thanks for mentioning it! Late static binding indeed could be useful in some cases, see docs: http://php.net/manual/en/la...
Cheers!
Thought so... The image of attaching a constant to a class rather than to an instance of that class makes definitely sense...
"Houston: no signs of life"
Start the conversation!