PHP Professional Standards & Competencies 5 — Questions and Answers
Question 1: Which PSR standard defines the Logger interface that most PHP logging libraries implement?
- PSR-3 (Correct answer)
- PSR-6
- PSR-11
- PSR-17
Correct answer: PSR-3
PSR-3 defines the `Psr\Log\LoggerInterface` with methods like `debug()`, `info()`, `warning()`, and `error()` that Monolog and others implement.
Question 2: What is the professional reason to avoid catching broad `Exception` or `Throwable` at the application logic level?
- PHP does not allow catching base exception classes
- Catching too broadly hides unexpected errors and prevents proper diagnosis of specific failure modes (Correct answer)
- Broad catches always cause memory leaks
- Only framework code is allowed to catch exceptions
Correct answer: Catching too broadly hides unexpected errors and prevents proper diagnosis of specific failure modes
Catching `Exception` globally masks bugs by treating programming errors as recoverable conditions; catch specific exception types relevant to the operation.
Question 3: A junior developer suggests storing user passwords as MD5 hashes for performance. What is the professional response?
- Accept it — MD5 is fast which is good for auth
- Reject it — use `password_hash()` with BCRYPT or ARGON2 because MD5 is cryptographically broken for password storage (Correct answer)
- Use SHA-256 instead of MD5 as a compromise
- Encrypt passwords with AES-256 and a secret key
Correct answer: Reject it — use `password_hash()` with BCRYPT or ARGON2 because MD5 is cryptographically broken for password storage
MD5 is not a password hashing algorithm; PHP's `password_hash()` with BCRYPT or ARGON2 uses salting and work factors designed to resist brute-force attacks.
Question 4: What does 'separation of concerns' mean in the context of PHP MVC applications?
- Split PHP files into equal-sized chunks
- Keep business logic (Model), presentation (View), and request handling (Controller) in distinct layers with minimal overlap (Correct answer)
- Use separate servers for each application feature
- Separate PHP code from HTML only at the template level
Correct answer: Keep business logic (Model), presentation (View), and request handling (Controller) in distinct layers with minimal overlap
SoC ensures each layer has a single responsibility: models handle data/business rules, views render output, and controllers coordinate the two.
Question 5: Which practice helps ensure backward compatibility when evolving a PHP REST API used by external clients?
- Delete old endpoints immediately when new ones are released
- Version the API (e.g., /v1/, /v2/) and maintain old versions for a deprecation period before removal (Correct answer)
- Change response field names freely in every release
- Require clients to always use the latest version within 24 hours
Correct answer: Version the API (e.g., /v1/, /v2/) and maintain old versions for a deprecation period before removal
API versioning gives existing clients time to migrate to new endpoints without breaking, following the principle that published contracts must be honored until formally retired.
Question 6: What is the professional purpose of a `.gitignore` file in a PHP project?
- Prevent Git from being installed on the server
- Exclude files that should not be tracked in version control, such as `vendor/`, `.env`, and build artifacts (Correct answer)
- Mark files as read-only in the repository
- Automatically merge conflicting PHP files
Correct answer: Exclude files that should not be tracked in version control, such as `vendor/`, `.env`, and build artifacts
A `.gitignore` keeps the repository clean by excluding generated directories like `vendor/`, sensitive files like `.env`, and IDE-specific config files.
Question 7: Which of the following best describes 'technical debt' in PHP projects and the professional approach to managing it?
- Money owed to the PHP Foundation for using the language
- Accumulated shortcuts and suboptimal code that must eventually be refactored; manage it by tracking, prioritizing, and addressing it incrementally (Correct answer)
- Third-party library licensing fees
- Server infrastructure costs associated with PHP hosting
Correct answer: Accumulated shortcuts and suboptimal code that must eventually be refactored; manage it by tracking, prioritizing, and addressing it incrementally
Technical debt is the implicit future cost of choosing quick solutions over correct ones; professionals track it explicitly and pay it down before it compounds to the point of blocking progress.
Which PSR standard defines the Logger interface that most PHP logging libraries implement?