Advanced Php Interview Questions 2025 Interview Questions & Answers
25 questions available
Mid
Answer
PHP itself is thread-safe only when compiled with ZTS, but most extensions are not thread-safe.
Hence Apache’’s mod_php rarely uses multi-threaded mode.
PHP-FPM solves concurrency by:
Running multiple worker processes, not threads.
Each request is isolated inside one worker.
No shared memory ? no race conditions.
It uses a master process to manage pools, recycling, and spawning.
Mid
Answer
PHP uses a root-buffer algorithm:
Roots represent zvals which are possible garbage.
The GC scans for zvals with refcount > 0 but not referenced externally.
If two objects reference each other but no external reference exists ? GC marks them collectible.
The GC root buffer triggers after threshold (~10k zvals).
Mid
Answer
interned_strings_buffer: Memory reserved for unique string instances.
All repeated strings across requests share the same memory.
memory_consumption: Total memory for storing:
compiled opcode arrays
function metadata
class metadata
cached results
Both reduce parse/compile time significantly.
Mid
Answer
PHP arrays are ordered hash tables.
Key conversion rules:
Numeric strings ('10') become integers.
Floats are truncated to integers.
true becomes 1
false becomes 0
null becomes an empty string.
Mid
Answer
Nginx/Apache hands off request to PHP-FPM via FastCGI.
PHP-FPM picks an idle worker.
Worker loads script, executes opcodes from OPCache.
Output returned via FastCGI.
Worker is cleaned (variables destroyed).
Worker reused or recycled based on max_requests.
Mid
Answer
PHP itself is synchronous, but async implementations use:
Event loops (ReactPHP, Amp)
Fibers (PHP 8.1+)
Non-blocking I/O via streams
Parallel extension for multi-threading
These simulate async behavior.
Mid
Answer
When an undefined class is used:
PHP triggers the spl_autoload_register chain.
Each autoloader tries to map class ? file path.
Files are included dynamically.
For composer, classmap + PSR-4 resolution is applied.
Mid
Answer
By default, PHP locks the session file:
First request acquires exclusive lock.
Other requests for same session block.
Lock is released on session_write_close().
This prevents race conditions like lost updates.
Mid
Answer
$GLOBALS is a superglobal associative array holding all global variables.
global imports variable references from global scope to local scope.
Mid
Answer
PHP performs a shallow copy:
All properties copied.
Private properties remain bound to original class.
__clone() is executed afterward if defined.
Mid
Answer
PHP arrays are always ordered hash tables, so:
Queue (push/pop) works but may cause reindexing.
Hash map uses string/int keys ? direct hash lookup.
Mid
Answer
No. PHP does not support TCO; recursion depth is limited (~100-200 by default).
Mid
Answer
include: Warning on failure, script continues.
require: Fatal error on failure.
_once: Prevents duplicate file inclusion using path lookup + hash table.
Mid
Answer
isset() is faster; it checks:
Key exists AND value is not null.
array_key_exists() checks:
Key exists, even if value is null.
Mid
Answer
Loose comparison (==):
"0" == false ? true
"123abc" == 123 ? true
Strict comparison (===) avoids conversion.
Mid
Answer
SPL:
O(1) insert/delete
Arrays:
O(n) due to reindexing and copying
Mid
Answer
Composer uses:
SAT (Boolean satisfiability solver)
Backtracking algorithm
Dependency constraint graph
If version ranges conflict ? install fails.
Mid
Answer
Variables share memory until modification:
$a = [1,2,3];
$b = $a; // shared
$b[0] = 10; // array copy created now
Mid
Answer
PHP ensures:
All interface methods must be implemented
Visibility must be public
Abstract classes may partially implement them
Mid
Answer
Class is included twice without using:
Namespaces
require_once
Composer autoloading
Class maps
Mid
Answer
PHP 7+:
Exception ? catchable
Error (fatal) ? also catchable
Both inherit from Throwable
Mid
Answer
Generators produce values lazily:
Only one element exists in memory at a time.
Large datasets don't need full arrays.
Mid
Answer
Files uploaded via multipart/form-data.
PHP stores uploads temporarily in /tmp.
Moves to target using move_uploaded_file() which verifies:
upload origin
temp filename reference
Mid
Answer
Reasons:
UTF-8 invalid byte sequence
Too deep recursion
Numeric overflow
NAN/INF values without using flags
Mid
Answer
PHP halts destructor execution
Remaining destructors may still run
Output buffer may flush partially
Shutdown functions continue