PHP Professional Standards & Competencies 3 — Questions and Answers
Question 1: What is the role of a CI/CD pipeline in professional PHP development?
- Replace unit tests with manual QA
- Automatically build, test, and deploy code on every change to catch regressions early (Correct answer)
- Generate API documentation from docblocks only
- Manage PHP version upgrades on the server
Correct answer: Automatically build, test, and deploy code on every change to catch regressions early
A CI/CD pipeline automates running tests, linters, and static analysis on every commit, and can automate deployment when checks pass.
Question 2: Which HTTP method should a professional PHP developer use for an idempotent delete operation in a REST API?
- POST
- GET
- DELETE (Correct answer)
- PATCH
Correct answer: DELETE
The DELETE method is the semantically correct HTTP verb for removing resources; it is also expected to be idempotent.
Question 3: What is the professional purpose of code reviews in a PHP team?
- To assign blame for bugs to individuals
- To catch defects, share knowledge, and enforce coding standards before code merges (Correct answer)
- To rewrite all code from scratch each sprint
- To eliminate the need for automated tests
Correct answer: To catch defects, share knowledge, and enforce coding standards before code merges
Code reviews spread institutional knowledge, catch logic errors, and ensure adherence to project conventions before code enters the main branch.
Question 4: When deprecating a public method in a PHP library, what is the professional standard approach?
- Delete the method immediately
- Add a `@deprecated` docblock tag and trigger a deprecation notice, then remove it in the next major version (Correct answer)
- Rename it without notice
- Keep it forever without any indication
Correct answer: Add a `@deprecated` docblock tag and trigger a deprecation notice, then remove it in the next major version
Adding `@deprecated` and a `trigger_error()` deprecation notice gives consumers time to migrate before the method is removed in a breaking major release.
Question 5: Which of the following is a key benefit of using Dependency Injection (DI) in PHP applications?
- It eliminates the need for unit tests
- It makes classes easier to test by supplying dependencies from outside rather than creating them internally (Correct answer)
- It automatically caches database queries
- It bypasses the need for interfaces
Correct answer: It makes classes easier to test by supplying dependencies from outside rather than creating them internally
DI allows test doubles (mocks/stubs) to be injected in place of real dependencies, making unit testing straightforward.
Question 6: What does SOLID stand for in object-oriented PHP development?
- Single, Open, Liskov, Interface, Dependency (Correct answer)
- Simple, Object, Loose, Integrated, Derived
- Structured, Organized, Layered, Isolated, Decoupled
- Sequential, Ordered, Linked, Inherited, Defined
Correct answer: Single, Open, Liskov, Interface, Dependency
SOLID is an acronym: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion principles.
Question 7: What is the professional rationale for writing tests before the production code (TDD)?
- Tests run faster when written first
- It forces you to think about the API and requirements before implementation, leading to better design (Correct answer)
- It automatically generates the production code
- It replaces the need for a specification document
Correct answer: It forces you to think about the API and requirements before implementation, leading to better design
Writing tests first (Red-Green-Refactor) ensures the code is testable by design and that it satisfies the specified behavior from the start.
What is the role of a CI/CD pipeline in professional PHP development?