PHP Technology & Digital Applications 3 — Questions and Answers
Question 1: Which PHP function sends a raw HTTP header to the client?
- echo()
- header() (Correct answer)
- send_header()
- http_response()
Correct answer: header()
The header() function sends a raw HTTP header and must be called before any output is sent.
Question 2: What PHP interface must be implemented to make an object iterable with foreach?
- Countable
- Traversable
- Iterator (Correct answer)
- ArrayAccess
Correct answer: Iterator
Implementing the Iterator interface with its five required methods (current, key, next, rewind, valid) allows foreach iteration.
Question 3: Which PHP function converts a Unix timestamp to a formatted date string?
- mktime()
- strtotime()
- date() (Correct answer)
- time()
Correct answer: date()
The date() function formats a Unix timestamp as a human-readable date string using format characters.
Question 4: In PHP, what is the purpose of the `ob_start()` function?
- Starts a database transaction
- Begins output buffering (Correct answer)
- Opens a file buffer
- Starts an object builder
Correct answer: Begins output buffering
ob_start() activates output buffering so that script output is captured in a buffer instead of sent directly to the browser.
Question 5: Which PHP function generates a cryptographically secure random integer?
- rand()
- mt_rand()
- random_int() (Correct answer)
- shuffle()
Correct answer: random_int()
random_int() uses a cryptographically secure pseudo-random number generator, unlike rand() or mt_rand().
Question 6: What does the PHP Composer tool manage?
- Database migrations
- PHP version upgrades
- Package dependencies (Correct answer)
- Web server configuration
Correct answer: Package dependencies
Composer is PHP's dependency manager, used to declare and install project libraries from Packagist.
Question 7: Which PHP function splits a string by a delimiter and returns an array?
- split()
- chunk()
- explode() (Correct answer)
- str_split()
Correct answer: explode()
explode() breaks a string into an array by a specified delimiter string.
Which PHP function sends a raw HTTP header to the client?