Great video but when I got to the exercises, I found a typo with Question 1. The correct answer says that one of the properties should be static but the explanation says that it should NOT be static. So I am a bit confused on what the correct answer should be.
Yes, one of the properties should be static, in particular, $numberOfHabitablePlanetsInUniverse because it is a global value for all planets, so setting it on each SolidPlanet object does not make sense. Is it more clear now?
Ahh. My bad. I was looking at the text for the wrong property when I was reading the explanation. Just go ahead and delete this whole comment thread. Thank you for the speedy reply.
In the second exercise it says: Update the GasPlanet::getHexColor() method to use self to reference the constants. As the method is not static can you actually write that? Wouldn't GasPlanet->getHexColor() be correct in this context? Thanks!
Ah, really good question, and something we should clarify I think! It's very common when you're talking about PHP code to say GasPlanet::getHexColor() to refer to the getHexColor method that lives in the GasPlanet class. We're using :: here... but we're not actually trying to say that getHexColor is static or non-static - it's just a lazy syntax when talking about functions (there's not a great alternative, since obviously GasPlanet->getHexColor() is closer, but is just completely nonsense code!).
When you're learning about static vs non-static... this is confusing. But hopefully now you can understand it when you see it other places!
Cheers!
Please, log in to vote for this comment
|
Share Comment
"Houston: no signs of life" Start the conversation!
7 Comments
Great video but when I got to the exercises, I found a typo with Question 1. The correct answer says that one of the properties should be static but the explanation says that it should NOT be static. So I am a bit confused on what the correct answer should be.
Hey @JDCrain
Yes, one of the properties should be static, in particular,
$numberOfHabitablePlanetsInUniversebecause it is a global value for all planets, so setting it on eachSolidPlanetobject does not make sense. Is it more clear now?Cheers!
Ahh. My bad. I was looking at the text for the wrong property when I was reading the explanation. Just go ahead and delete this whole comment thread. Thank you for the speedy reply.
NP! You're welcome!
Props to the explaination. Nice and clear.
In the second exercise it says:
Update the GasPlanet::getHexColor() method to use self to reference the constants.
As the method is not static can you actually write that? Wouldn't GasPlanet->getHexColor() be correct in this context? Thanks!
Yo again Max!
Ah, really good question, and something we should clarify I think! It's very common when you're talking about PHP code to say
GasPlanet::getHexColor()to refer to thegetHexColormethod that lives in theGasPlanetclass. We're using::here... but we're not actually trying to say thatgetHexColoris static or non-static - it's just a lazy syntax when talking about functions (there's not a great alternative, since obviously GasPlanet->getHexColor() is closer, but is just completely nonsense code!).When you're learning about static vs non-static... this is confusing. But hopefully now you can understand it when you see it other places!
Cheers!
"Houston: no signs of life"
Start the conversation!