PHP Quiz
A short PHP quiz - types, arrays, OOP, and modern PHP.
Sample questions
EXAMPLE
# PHP quiz 1) PHP 8.x introduced: a) typed properties + nullsafe + match + readonly + enums + named args b) only an interpreter speedup c) removed arrays d) goto statement 2) Which is the modern way to convert a string to int? a) (int)$s or intval($s, 10) b) parseInt($s) c) toint($s) d) atoi($s) 3) === vs ==: a) the same b) === checks type AND value; == coerces types before comparing c) === is deprecated d) === only works on strings 4) The nullsafe operator ?-> a) replaces if (isset(...)) b) short-circuits if the left side is null, returning null c) only works on arrays d) was removed in PHP 8.2 5) Named arguments allow: a) reordering b) calling functions with arg-name: value pairs, skipping defaults c) creating constants d) reflection only 6) match() differs from switch() because: a) match uses strict comparison and returns a value b) match supports loops c) match is for arrays d) it does not exist 7) readonly properties: a) are constants b) can be set once in the constructor, never reassigned c) only work on strings d) compile to private 8) Composer is: a) a music tool b) PHP's dependency manager + autoloader c) deprecated d) a framework Answers: 1a, 2a, 3b, 4b, 5b, 6a, 7b, 8b.
Why it matters
Modern PHP (8.x+) is a different language than PHP 5. Strict types, readonly, enums, nullsafe, match, and named args remove most of the legacy gripes. Composer + PSR autoloading is the foundation for any new project.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
<?php // Quizzes appear at the end of each lesson — 3 questions each. echo 'Test yourself when you finish a lesson!';Try it Yourself »
Exercise
Per-lesson quiz length.
questions
A single digit.
Discussion
Loading…