10.
Type Hinting?!
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.
9 Comments
Hey!
At 6:11 you remove the array key and replace it with the getter-function. PHPStorm not seems to recognize it as it's yellow afterwards and does not suppose autocompletion. Is there a possibility to fix that?
Yo Max S.!
There is a fix! And great question - I'm kind of obsessed with getting auto-completion in PhpStorm (it also helps me know when I'm doing something right versus wrong).
So, the
$ship1and$ship2variables come from the$shipsvariable near the top of the file. The summary looks like this:If we could somehow tell PhpStorm that the
get_ships()method returns an array ofShipobjects, then it would be smart enough to know that$ship1and$ship2must themselves beShipobjects (since we fetch them from$shipswith array keys). To do that, add this aboveget_ships()``/**
*/
get_ships()
{
// ...
}
The
[]after is what says "this is an array of Ship" objects.Let me know if that helps!
Super awesome! I think I am going to join your obsession :D Thank you very much!
I was getting an error on 'quantity". I changed the isset check in lines 8 and 10 to !empty.
$ship1Quantity = !empty($_POST['ship1_quantity']) ? $_POST['ship1_quantity'] : 1;
Hey Si Y.
What error were you getting? You need to add the
isset()check because it's possible that the fieldship1_quantityis not submitted.Cheers!
The code wasn't actually erroring. It was working by redirecting back to index with a $GET suffix because the 'ship1_quantity' field in the $POST was an empty string. Changing the isset check to a !empty check catches the empty string as well as the existence of the variable. (Did I get that right?) You can check it in the code, it fails if the quantity fields are left blank (empty strings rather than nulls).
Ohh, yes, you are totally right, the
empty()allow you to "access" to undefined index of arrays without throwing. That's nice :)So, yes, if you do that change then,
$ship1Quantitywill default to 1. Nice debugging! Cheers!What chrome extension are you using that gives you the nicely formatted var_dump and error messages?
Actually, it's XDebug - it's a PHP extension. I highly recommend installing it on your development machine :)
"Houston: no signs of life"
Start the conversation!