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?

2. Why should a file containing only PHP code leave out the closing ?> tag?

3. What does echo 'Hi $name'; print?

4. What does var_dump(7 / 2); show?

5. Which of these values is truthy?

6. Why prefer === to ==?

7. What's the difference between ?? and ?:?

8. What happens when a match expression gets a value no arm handles?

9. Why is if (strpos($s, 'apple')) a bug?

10. Why use mb_strlen instead of strlen for user names?

11. After $a = [1, 2]; $b = $a; $b[] = 3;, what is count($a)?

12. What does array_filter do to the keys of the elements it keeps?

13. What does sort($numbers) return?

14. What does declare(strict_types=1) do?

15. Can a function read a variable defined outside it, without passing it in?

16. What does fn($x) => $x * $rate do with $rate?

17. What does PHP 8.5's $x |> f(...) mean?

18. What does constructor promotion do in public function __construct(public string $name) {}?

19. What does public private(set) float $balance mean?

20. What is the main difference between an interface and an abstract class?

21. Why use a backed enum (enum Status: string) instead of a pure enum?

22. Inside the namespace App\Services, what does new Exception() look for?

23. What's the advantage of a generator over returning a big array?

24. Which statement about form data is true?

25. What prevents cross-site scripting (XSS) when displaying a user's comment?

26. Why call session_regenerate_id(true) after a successful login?

27. Why is trusting a cookie like is_admin=1 a serious mistake?

28. What should usually follow header('Location: /done.php');?

29. What's the only reliable defence against SQL injection?

30. How should passwords be stored?

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.