Interview Q&A · questions with model answers
PHP 8 Interview Questions
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Why were dynamic properties deprecated in PHP 8.2 and how do you handle it?
Creating properties that aren't declared on a class now emits a deprecation (and is planned to become an Error in PHP 9), because it usually hides typos and makes objects unpredictable.
-
Why is `unserialize()` on user input dangerous?
unserialize() can instantiate arbitrary classes and trigger magic methods like wakeup/destruct, enabling PHP object injection and gadget-chain remote code execution.
-
Why prefer `DateTimeImmutable` over `DateTime`?
DateTimeImmutable returns a new object from modify()/add(), so shared dates can't be changed accidentally; DateTime mutates in place, which causes subtle bugs.
-
Why are static properties and singletons discouraged?
They create hidden global state that makes code hard to test, couples classes tightly, and causes cross-request leaks in long-running runtimes like Octane, Swoole or RoadRunner.
-
Why does running a supported PHP version matter?
Each PHP minor version gets two years of active support and then two more years of security-only fixes (since PHP 8.1 the security phase was extended). Running an EOL version means unpatched…