Quiz: PHP
PHP questions from real interviews as a quiz, with an explanation for every option.
Try it: 5 questions
Loading…
Sample questions
What is the primary role of the Model in the MVC architecture?
- Handle HTTP requests and select the appropriate view
- Configure routes and manage navigation between pages
- Build HTML pages and display data to the user
- Manage the application's data and business logic
How does separating a class according to SRP typically affect the risk of regressions when requirements change?
- It has no effect: only test coverage affects regression risk
- It increases the risk: every change requires modifying more classes
- It reduces the risk: a change to one responsibility is less likely to affect unrelated parts
- It eliminates the risk: a class with one responsibility cannot contain bugs
How is a many-to-many relationship between two tables typically implemented in MySQL?
- Create a junction table with foreign keys referencing both tables
- Add a foreign key to the second table in the first table
- Copy the data from both tables into a separate shared table
- Add a column containing a list of IDs to each table
What is a protocol in a computer network?
- A physical channel that carries network signals
- An address used to locate a device on a network
- A program that stores network data on a server
- A set of rules defining the format and order of data exchange
Which three approaches can speed up searches on a string field in a database?
- Create an index suited to the search condition.
- Cache results of frequently repeated queries.
- Split every string value into separate rows; this always speeds up searching.
- Avoid applying functions to a field in
WHEREwhen that prevents index use. - Add a
FULLTEXTindex to speed up every search using a%text%pattern.
In software design, what does coupling mean, and what level is generally preferred?
- The number of methods in a module; as few methods as possible are generally preferred.
- How closely related the elements within a module are; low cohesion is generally preferred.
- The degree to which modules depend on one another; low coupling is generally preferred.
- The number of interfaces between modules; as many interfaces as possible are generally preferred.
What typically allows a database to find a row quickly by its primary key value?
- An index on the primary key column
- A full table scan
- Caching every row in the table
- A relationship with foreign keys
In MySQL, what is the main difference between
EXPLAINandEXPLAIN ANALYZE?EXPLAIN ANALYZEruns the query only when an index is available; otherwise, it returns estimates.- Both commands run the query, but
EXPLAIN ANALYZEalso lists the indexes used. EXPLAINshows estimated plan details without running the query, whileEXPLAIN ANALYZEruns it and reports actual metrics.EXPLAINreports actual metrics, whileEXPLAIN ANALYZEonly shows optimizer estimates.
Which benefits does PDO provide when working with databases in PHP? Select all that apply.
- Configurable error-handling modes
- A common interface for working with different database systems
- Automatic reconnection and retrying failed queries
- Prepared statements that help protect against SQL injection
- Automatic conversion of SQL queries to each database system’s dialect
Which option best describes a unit test?
- It automatically checks a small piece of code separately from the rest of the system.
- It checks how fast an application performs under heavy load.
- It manually checks an application by following a predefined scenario.
- It checks how all the main parts of an application work together.