PHP Research & Evidence-Based Practice 3 — Questions and Answers
Question 1: Which built-in PHP function helps developers research the structure and properties of an unknown object at runtime?
- print_r()
- var_dump() (Correct answer)
- get_object_vars()
- object_inspect()
Correct answer: var_dump()
var_dump() outputs detailed type and value information for variables including objects, making it ideal for runtime inspection.
Question 2: In PHP, which PSR standard defines the coding style guidelines most commonly referenced in research and best-practice documentation?
- PSR-1 and PSR-12 (Correct answer)
- PSR-2 and PSR-4
- PSR-3 and PSR-6
- PSR-7 and PSR-15
Correct answer: PSR-1 and PSR-12
PSR-1 establishes basic coding standards and PSR-12 (which superseded PSR-2) defines extended coding style guidelines for PHP.
Question 3: Which command-line tool allows PHP developers to search the official documentation and function signatures directly from the terminal?
- php --man
- php -r 'phpinfo()'
- pman (Correct answer)
- php --info
Correct answer: pman
pman (PHP manual) is a command-line tool that provides access to PHP documentation in man-page format from the terminal.
Question 4: What does the PHP function get_defined_functions() return that is useful for researching available functions in a PHP environment?
- A count of user-defined functions only
- An associative array of internal and user-defined functions (Correct answer)
- A list of deprecated functions
- The functions defined in a specific namespace
Correct answer: An associative array of internal and user-defined functions
get_defined_functions() returns an array with 'internal' and 'user' keys listing all functions available in the current PHP environment.
Question 5: When reviewing PHP library dependencies for security vulnerabilities, which tool is the industry standard for scanning composer.lock files?
- php-cs-fixer
- Roave Security Advisories
- composer audit (Correct answer)
- PHPStan
Correct answer: composer audit
The 'composer audit' command checks the composer.lock file against the PHP Security Advisories Database and reports known vulnerabilities.
Question 6: In PHP static analysis, which tool analyzes code without executing it and reports type errors and potential bugs based on inference?
- PHPUnit
- PHPStan (Correct answer)
- Xdebug
- PHPMD
Correct answer: PHPStan
PHPStan performs static analysis of PHP code, detecting type mismatches and potential bugs without running the application.
Question 7: Which PHP function provides a stack trace of the current call chain, useful for debugging and research into code execution flow?
- debug_backtrace() (Correct answer)
- get_call_stack()
- trace_calls()
- stack_trace()
Correct answer: debug_backtrace()
debug_backtrace() returns an array representing the current call stack, including file, line, function, and argument information.
Which built-in PHP function helps developers research the structure and properties of an unknown object at runtime?