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.
-
Most asked How does `match` differ from `switch`?
match is an expression that returns a value, uses strict (===) comparison, has no fall-through, and throws UnhandledMatchError if no arm matches.
-
Most asked What are enums in PHP 8.1? Explain pure vs backed enums.
Enums define a closed set of named values as a first-class type. Pure enums have only cases; backed enums map each case to a scalar int or string value.
-
Most asked When would you use an interface, an abstract class, or a trait in PHP?
Use an interface to define a contract, an abstract class to share base state and partial implementation in an is-a hierarchy, and a trait to reuse code horizontally across unrelated classes.
-
Most asked How did string-to-number comparison change in PHP 8?
When comparing a number with a non-numeric string, PHP 8 now compares them as strings instead of casting the string to a number, so 0 == 'foo' is false (it was true in PHP 7).
-
Most asked Compare `??`, `?:`, and `?->`.
?? returns the left operand unless it is null/undefined, ?: returns the left operand unless it is falsy, and ?-> safely calls a method or property on a possibly-null object.
-
Which magic methods matter most in modern PHP?
The most important are construct, toString, invoke, get/set, call/callStatic, serialize/unserialize, clone and destruct.
-
What is the difference between `composer install` and `composer update`, and why commit `composer.lock`?
install installs the exact versions recorded in composer.lock; update resolves the newest versions allowed by composer.json constraints and rewrites the lock file.
-
Which PSRs should a PHP developer know?
Key PSRs: PSR-1/PSR-12 (now PER Coding Style) for code style, PSR-4 autoloading, PSR-3 logging, PSR-7/17 HTTP messages and factories, PSR-15 middleware, PSR-18 HTTP client, PSR-11 container,…
-
Which SPL data structures and interfaces are useful in practice?
Useful SPL tools include ArrayIterator, SplObjectStorage, SplPriorityQueue, SplQueue/SplStack, SplFixedArray, and the interfaces IteratorAggregate, ArrayAccess and Countable.
-
What are Value Objects and DTOs, and how do they differ?
Value objects are immutable domain types defined by their values, with validation and behavior (e.g., Money, Email). DTOs are simple data carriers between layers, with no behavior.
-
Compare Laravel and Symfony from an architecture standpoint.
Both are mature PHP 8 frameworks. Laravel favors convention, rapid development and expressive facades/Eloquent (active record). Symfony favors explicit configuration, decoupled reusable components…
-
Which php.ini and HTTP settings harden a production PHP app?
Set display_errors=Off, log_errors=On, expose_php=Off, zend.exception_ignore_args=On, a strict open_basedir/disable_functions where appropriate, secure session settings, and security headers (HSTS,…
-
Compare PHP-FPM with long-running runtimes like Swoole, RoadRunner and FrankenPHP.
PHP-FPM boots the app on every request (shared-nothing). RoadRunner, Swoole/OpenSwoole and FrankenPHP worker mode keep the application in memory between requests, giving big throughput gains but…
-
When are anonymous classes useful?
Anonymous classes (new class(...) implements Foo { ... }) are useful for one-off implementations, especially lightweight test doubles, adapters and inline event listeners.
-
Which array functions should every PHP developer know well?
Core ones: array_map, array_filter, array_reduce, array_column, array_combine, array_key_exists vs isset, in_array(..., true), usort with the spaceship operator, array_slice/array_splice, and 8.4's…
-
What options exist for concurrency or parallelism in PHP?
Options include multiple processes (FPM, pcntl_fork, queue workers, symfony/process), the parallel extension (threads, requires ZTS), async I/O with Fibers-based libraries (AMPHP, ReactPHP, Revolt),…
-
What is the difference between `include`, `require`, `include_once` and `require_once`?
require stops with a fatal error if the file is missing while include only emits a warning and continues; the _once variants skip files that were already loaded.