PHP and Backend Development Multiple-Choice Interview Questions with Answers and Explanations
This article presents a collection of 19 multiple‑choice interview questions covering PHP error handling, shell functions, full‑text search, design patterns, database locking, cron scheduling, network I/O models, and more, each with the correct answer and concise analysis for backend developers.
1. Which function can convert errors to exceptions? Options: A) set_error_handler , B) error_reporting , C) error2exception , D) catch . Correct answer: A. Explanation: set_error_handler() can specify a callback that throws a new exception when an error occurs.
2. Which statement about shell functions is correct? Options: A) Shell functions can be called before they are defined, B) Shell functions must be defined with the function keyword, C) Variables inside a shell function can be declared as local, D) Shell functions can only return values where 1 means success and 0 means failure. Correct answer: C. Explanation: Shell functions must be defined before they are called; no keyword is required; the local command can create function‑local variables; return values follow the convention 0 = success, non‑zero = error.
3. Which statement about full‑text search technology is incorrect? Options: A) Solr is a next‑generation full‑text component that is much faster than Lucene and supports HTTP access, B) MySQL FULLTEXT indexes are supported by both MyISAM and InnoDB tables, C) Sphinx is an SQL‑based full‑text engine that can be combined with MySQL, D) Lucene’s CJKAnalyzer tokenizes quickly. Correct answer: A. Explanation: Solr is built on Lucene, so it is not inherently faster than Lucene.
4. Which statement about the Singleton pattern is wrong? Options: A) It ensures only one instance of a class exists globally, B) The constructor is usually made private , C) Making the constructor private alone guarantees a single global instance, D) Database connection functionality is often implemented with a singleton. Correct answer: C. Explanation: A private constructor prevents direct new , but instances can still be created via cloning or deserialization.
5. Which description of a regular‑expression engine is wrong? Options: A) Engines are divided into DFA and NFA, B) Generally NFA engines are faster, C) NFA is expression‑driven, DFA is text‑driven, D) Support for ignoring quantifiers and group capture distinguishes NFA from DFA. Correct answer: B. Explanation: In practice DFA engines are usually faster; NFA engines are more flexible for complex patterns.
6. Which option matches the regular expression /.Sd/ ? Options: A) 123, B) **1234, C) 1234, D) 123. Correct answer: B. Explanation: The pattern means any character (.), followed by a literal asterisk (*), then "123"; only option B contains a literal asterisk before "123".
7. Which statement about databases is incorrect? Options: A) Multiple read replicas can improve efficiency, B) Master‑slave replication provides hot‑standby, C) Databases cannot provide multi‑master multi‑slave architectures, D) Master‑slave replication synchronizes via logs. Correct answer: C. Explanation: Modern databases can support multi‑master configurations.
8. Which is NOT a proper XSS mitigation method? Options: A) Apply htmlspecialchars filtering, B) Use whitelist filtering, C) Disallow any user‑generated content from being displayed, D) Prohibit output of user input inside <script> tags. Correct answer: A. Explanation: htmlspecialchars mitigates tag‑based XSS but does not protect against JavaScript‑based injection.
9. Which is NOT a PHP SAPI mode? Options: A) ISAPI, B) CGI, C) FastCGI, D) RESTFUL API. Correct answer: D. Explanation: ISAPI, CGI, and FastCGI are actual SAPI implementations; RESTful API is an architectural style.
10. Which method offers the best performance for iterating a large file line‑by‑line? Options: A) Implement IteratorAggregate and use foreach , B) Load the entire file with file_get_contents , C) Use exec to call a shell tool, D) Use a third‑party library. Correct answer: A. Explanation: An IteratorAggregate implementation reads the file incrementally, avoiding memory exhaustion.
11. Which principle is NOT a guideline for design patterns? Options: A) Composition over inheritance, B) Program to interfaces, C) Minimize coupling, D) Prefer high‑performance syntax. Correct answer: D. Explanation: Design patterns focus on maintainability and reusability, not raw performance.
12. Which backtracking expression is incorrect? Options: A) ab.lmn , B) ab.?lmn , C) ab??c , D) .*lmn . Correct answer: D. Explanation: .*lmn is a greedy match and will consume as much as possible, matching the entire string up to the last "lmn".
13. In a try‑catch‑finally block, where should return be placed? Options: A) In finally , B) In try , C) In catch , D) Anywhere. Correct answer: A. Explanation: If return appears in try , the finally block still executes; a return in finally overrides earlier returns.
14. Which statement about NoSQL is incorrect? Options: A) Redis supports strings, hashes, lists, sets, sorted sets but does NOT support transactions, B) MongoDB supports AP in CAP, MySQL supports CA, C) MongoDB allows inserting without pre‑creating collections but does NOT support transactions, D) Memcache supports both TCP and UDP and can store PHP sessions. Correct answer: A. Explanation: Redis does support transactions via MULTI/EXEC .
15. Which statement about InnoDB locking is wrong? Options: A) InnoDB provides both table‑level and row‑level locks, B) Table locks are triggered on table changes, C) Updates acquire exclusive row locks and create a snapshot that SELECT reads, D) Row‑level locks affect reads but not writes. Correct answer: A. Explanation: InnoDB primarily uses row‑level locking; table‑level locks are rare.
16. Which crontab command runs every 3 minutes between 01:00 and 04:00 on Wednesdays? Options: A) 1,4 3 /bin/bash /home/sijiaomao/ok.sh , B) /3 1,4 3 /bin/bash /home/sijiaomao/ok.sh , C) /3 1-4 3 /bin/bash /home/sijiaomao/ok.sh , D) /3 1-4 * /bin/bash /home/sijiaomao/ok.sh . Correct answer: C. Explanation: The schedule /3 1-4 3 means every 3 minutes during hours 1‑4 on day‑of‑week 3 (Wednesday).
17. After service splitting, which method does NOT effectively solve cross‑database join problems? Options: A) Global tables shared across modules, B) Data redundancy (store seller name in order table), C) Master‑slave replication with read/write separation, D) Data synchronization of related tables. Correct answer: C. Explanation: Master‑slave replication only scales reads; it does not eliminate the need for joins across separate databases.
18. Which statement about network I/O models is correct? Options: A) Select is faster than epoll , B) Nginx uses select , C) Apache can switch between select and epoll , D) epoll supports higher concurrency. Correct answer: D. Explanation: epoll is designed for large numbers of simultaneous connections.
19. The correct order of PHP execution phases (Scanning, Parsing, Compilation, Execution) is: Options: A) Tokens → Expressions → Opcodes → Execution, B) Tokens → Expressions → Execution → Opcodes, C) Tokens → Opcodes → Execution → Expressions, D) Tokens → Opcodes → Expressions → Execution. Correct answer: C. Explanation: The proper sequence is Scanning (lexing) → Parsing → Compilation → Execution.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.