So sleepy. Hey, i never did anything with the “teach PHP” project I was pondering in January. Hmm.
Posted by
Beryllium (aka grayman)
Apr 6 '18, 19:07
|
OK, here’s a PHP program. It’s boring and it has a bug. Can you spot the bug? (Technically it has two bugs, because of fucking smartquotes)
<?php
$stocks = [
‘Cmarv’ => 171.24,
‘Antm2’ => 172.08,
‘Avng3’ => 569.14,
];
Foreach ($stocks as $ticker => $price) {
echo “Stock price for “ . $ticker “: “ . number_format($price) . “\n”;
}
1. Go to 3v4l.org
2. Paste that code snippet into it and click “Preview”
3. Watch it fail and try to use the error messages to get it not to fail.
The first step will be replacing the ‘ and “ bullshit with ' and ",
but after that there are one or two other problems to fix as well. And then it can start as a baseline for learning other tricks.
When the preview mode passes, click the main blue button to have it run against all recent PHP versions - this essentially saves it to a linkable URL that you can post back here.
(If you hit too many issues with it, you can also hit the blue button & link here for help)
|
Responses:
|