PHP Quiz
Thirty questions covering the whole course. Choose an answer for each, then press Check answers at the bottom to see your score and an explanation for every question.
1. Where does PHP code run?
The browser never sees the PHP code, only its output (lesson 01).
2. Why should a file containing only PHP code leave out the closing ?> tag?
(lessons 03 and 50)
3. What does echo 'Hi $name'; print?
Variables are only interpolated in double-quoted strings and heredocs (lesson 16).
4. What does var_dump(7 / 2); show?
Use intdiv() for integer division (lesson 08).
5. Which of these values is truthy?
"0" is falsy but "0.0" is not (lesson 09).
6. Why prefer === to ==?
(lesson 09)
7. What's the difference between ?? and ?:?
So 0 ?? 5 is 0, but 0 ?: 5 is 5 (lesson 10).
8. What happens when a match expression gets a value no arm handles?
Add a default arm when a fallback makes sense (lesson 13).
9. Why is if (strpos($s, 'apple')) a bug?
Compare with !== false, or use str_contains (lesson 17).
10. Why use mb_strlen instead of strlen for user names?
(lesson 19)
11. After $a = [1, 2]; $b = $a; $b[] = 3;, what is count($a)?
Arrays are copied on assignment; objects are not (lessons 21 and 33).
12. What does array_filter do to the keys of the elements it keeps?
Wrap the result in array_values() for a clean list (lesson 23).
13. What does sort($numbers) return?
(lesson 24)
14. What does declare(strict_types=1) do?
(lesson 29)
15. Can a function read a variable defined outside it, without passing it in?
Pass values in as parameters instead (lesson 30).
16. What does fn($x) => $x * $rate do with $rate?
Full closures need use ($rate) (lesson 31).
17. What does PHP 8.5's $x |> f(...) mean?
(lesson 31)
18. What does constructor promotion do in public function __construct(public string $name) {}?
(lesson 34)
19. What does public private(set) float $balance mean?
Asymmetric visibility, PHP 8.4 (lesson 35).
20. What is the main difference between an interface and an abstract class?
(lesson 38)
21. Why use a backed enum (enum Status: string) instead of a pure enum?
(lesson 40)
22. Inside the namespace App\Services, what does new Exception() look for?
(lesson 43)
23. What's the advantage of a generator over returning a big array?
(lesson 45)
24. Which statement about form data is true?
(lessons 46–47)
25. What prevents cross-site scripting (XSS) when displaying a user's comment?
(lesson 47)
26. Why call session_regenerate_id(true) after a successful login?
(lesson 48)
27. Why is trusting a cookie like is_admin=1 a serious mistake?
Keep authorisation data in the server-side session (lesson 49).
28. What should usually follow header('Location: /done.php');?
(lesson 50)
29. What's the only reliable defence against SQL injection?
(lesson 58)
30. How should passwords be stored?
(lesson 59)
How did you do?
- 27–30: excellent — you've got a solid grasp of PHP. Try the guestbook challenges.
- 20–26: good — revisit the lessons mentioned in the explanations you missed.
- Below 20: work through the exercises and re-read the parts of the course that felt shaky, then try again.