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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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…

Was this page helpful?

Report a mistake