81. Which PHP caching mechanism improves performance by storing precompiled script bytecode?
- a) OPcache
- b) Memcached
- c) APC
- d) Redis
Answer: A - OPcache stores precompiled PHP scripts in shared memory, reducing parsing overhead.
82. What is the purpose of PHP's output buffering?
- a) Stores output before sending to browser
- b) Compresses HTTP responses
- c) Caches database queries
- d) Buffers file uploads
Answer: A - ob_start() captures output, allowing manipulation before sending headers/content.
83. Which design pattern ensures only one instance of a class exists?
- a) Singleton
- b) Factory
- c) Observer
- d) Strategy
Answer: A - Singleton pattern restricts instantiation to one object (e.g., database connections).
84. How do you implement a REST API in PHP?
- a) Use $_SERVER['REQUEST_METHOD'] to handle HTTP verbs
- b) Implement a REST controller class
- c) Use a framework like Slim or Lumen
- d) All of the above
Answer: D - All approaches are valid (manual implementation or frameworks).
85. Which PHP function measures script execution time?
- a) microtime(true)
- b) time()
- c) exec_time()
- d) benchmark()
Answer: A - microtime(true) returns current Unix timestamp with microseconds (for benchmarking).
86. What is the purpose of PHP's Generator functions?
- a) Memory-efficient iteration
- b) Generate random numbers
- c) Create class constructors
- d) Handle exceptions
Answer: A - Generators (yield keyword) provide lazy evaluation for memory optimization.
87. Which Laravel feature provides API authentication?
- a) Passport
- b) Sanctum
- c) JWT Auth
- d) All of the above
Answer: D - Laravel supports multiple API authentication methods.
88. What is PHP's JIT (Just-In-Time) compilation?
- a) Compiles PHP to machine code at runtime
- b) JavaScript integration
- c) Template engine
- d) Database query optimization
Answer: A - JIT (introduced in PHP 8) improves performance by compiling hot code paths to native machine code.
89. Which design pattern is implemented by PHP's SplObserver/SplSubject?
- a) Observer
- b) Decorator
- c) Adapter
- d) Singleton
Answer: A - SplObserver/SplSubject implement the Observer pattern (publish-subscribe).
90. What is the purpose of HTTP middleware in PHP frameworks?
- a) Process requests/responses in a pipeline
- b) Route URLs to controllers
- c) Generate API documentation
- d) Manage database connections
Answer: A - Middleware filters HTTP requests (e.g., authentication, CORS, logging).
91. Which PHP extension provides multibyte string functions?
- a) mbstring
- b) iconv
- c) string
- d) utf8
Answer: A - mbstring provides multibyte-safe string operations (e.g., mb_strlen()).
92. What is the purpose of PHP's array_reduce() function?
- a) Iteratively reduces array to a single value
- b) Removes duplicate values
- c) Sorts an array
- d) Merges multiple arrays
Answer: A - array_reduce() applies a callback to reduce elements (e.g., sum calculation).
93. Which PHP function creates a stream context for file operations?
- a) stream_context_create()
- b>fopen_context()
- c>create_stream()
- d>file_context()
Answer: A - stream_context_create() sets options for HTTP/FTP streams and wrappers.
94. What is the purpose of PHP's register_shutdown_function()?
- a) Registers function to execute after script completion
- b>Handles fatal errors
- c>Both A and B
- d>Registers class autoloaders
Answer: C - It runs after script execution (even on fatal errors) for cleanup tasks.
95. Which PHP feature allows dynamic method/property calls?
- a) __call() and __get() magic methods
- b>Reflection
- c>Dynamic properties
- d>Function overloading
Answer: A - __call() handles undefined methods, __get() accesses undefined properties.
96. What is PHP's Phar extension used for?
- a) Packaging PHP applications into archives
- b>PHAR file execution
- c>Both A and B
- d>Performance benchmarking
Answer: C - Phar (PHP Archive) bundles applications into single executable files.
97. Which PHP function provides memory usage information?
- a) memory_get_usage()
- b>get_memory()
- c>php_memory()
- d>memory_usage()
Answer: A - memory_get_usage() returns allocated memory in bytes.
98. What is the purpose of PHP's declare(ticks=1) directive?
- a) Enables tick-based event handling
- b>Sets CPU time limits
- c>Enables strict typing
- d>Configures garbage collection
Answer: A - Ticks trigger registered functions on each N low-level statements (rarely used).
99. Which PHP.ini setting limits maximum execution time?
- a) max_execution_time
- b>time_limit
- c>script_timeout
- d>execution_limit
Answer: A - max_execution_time sets timeout in seconds (0 = no limit).
100. What is the purpose of PHP's FFI (Foreign Function Interface)?
- a) Calls C functions directly
- b>Handles file operations
- c>Manages foreign key constraints
- d>Processes web forms
Answer: A - FFI (PHP 7.4+) interacts with C libraries without writing extensions.