Home
Categories
Register
Login
Symfony 7 – PHP – PHP API up to 8.2
20 multiple-choice questions focused strictly on the PHP core/API up to version 8.2.
Question 1:
What does declare(strict_types=1) change in a PHP file?
It globally enforces strict typing across the whole project.
It disables JIT compilation.
It enforces exact scalar types for arguments and returns in calls from that file.
It forbids union types.
Question 2:
How does match differ from switch in PHP?
match allows loose comparisons like switch.
match requires explicit break statements.
match can only compare integers.
match uses strict identity (===) and returns a value; no fall-through.
Question 3:
What is the behavior of the nullsafe operator (?->)?
If the left side is null, the expression evaluates to null.
It throws a TypeError on null.
It converts null into an empty object.
It only works with array access.
Question 4:
What does the null coalescing operator (??) do?
Returns right when left is any falsy value.
Performs a strict comparison and returns boolean.
Returns left if it is set and not null; otherwise right.
Evaluates both sides eagerly regardless of null.
Question 5:
What does the null coalescing assignment (??=) do?
Assigns right to left only if left is null.
Assigns right to left when left is falsy.
Throws on null to force initialization.
Is identical to ||= in behavior.
Question 6:
Which statement about named arguments is correct?
They can only be used in constructors.
They require attributes to be enabled.
They allow passing arguments by parameter name in any order.
They are limited to scalar parameters.
Question 7:
How are union types written in PHP?
With commas: int,string.
With the vertical bar: int|string.
With ampersand: int&string.
With array syntax: [int|string].
Question 8:
What do Disjunctive Normal Form (DNF) types allow in PHP 8.2?
Only unions, no intersections.
Only intersections, no unions.
Generics with angle brackets.
Combining unions and intersections like (A&B)|C.
Question 9:
What does declaring a class as readonly in PHP 8.2 enforce?
Methods cannot modify local variables.
The class cannot be instantiated.
All non-static properties are readonly (single assignment).
Only private properties become readonly.
Question 10:
How are dynamic properties treated in PHP 8.2 by default?
They trigger a deprecation notice unless allowed by an attribute.
They are silently created as before.
They cause a fatal error in all cases.
They are automatically made typed properties.
Question 11:
What is the purpose of #[AllowDynamicProperties]?
Allow dynamic properties on the annotated class without deprecation.
Forbid dynamic properties on the class.
Convert dynamic properties to typed ones.
Enable JIT for property access.
Question 12:
What does #[SensitiveParameter] achieve?
It encrypts the parameter in memory.
It forces pass-by-reference.
It prevents the function from throwing.
It redacts the parameter value from traces and logs.
Question 13:
Which is the correct way to store and verify passwords in PHP?
Store with md5() and compare with ===.
Use password_hash() to store and password_verify() to check.
Encrypt with openssl_encrypt() and decrypt to compare.
Store plain text but use HTTPS.
Question 14:
How do you make json_decode throw on malformed JSON?
Call json_last_error_msg() first.
Use json_decode($json, true, 512, JSON_THROW_ON_ERROR).
Wrap in try/catch without any flags.
Pass true as the second parameter only.
Question 15:
Which is the standard way to validate an email string?
preg_match("/.+@.+/", $email).
str_contains($email, "@").
json_decode($email).
filter_var($email, FILTER_VALIDATE_EMAIL).
Question 16:
Which function provides cryptographically secure integers?
rand
random_int
mt_rand
lcg_value
Question 17:
How should you compare MACs (message authentication codes) safely?
Use === to compare strings directly.
Use strcmp which is always constant-time.
Use hash_equals($a, $b) for constant-time comparison.
Trim both strings then compare.
Question 18:
What is a key advantage of DateTimeImmutable over DateTime?
It cannot be formatted.
Methods return new instances instead of mutating the object.
It is deprecated.
It only supports UTC.
Question 19:
Which function should you use to get multibyte-safe string length?
mb_strlen
strlen
iconv_strlen without setting encoding
substr_count
Question 20:
What is the main purpose of array_map compared to array_walk?
Both modify the original array by reference.
array_map returns a new transformed array; array_walk is for in-place side effects.
array_map only works with associative arrays.
array_walk performs mapping and returns the mapped array.
Submit Answers