Challenge - 5 Problems
PHP Request Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this PHP script?
Consider this PHP code that runs during a request. What will it output?
PHP
<?php register_shutdown_function(function() { echo "End of request."; }); echo "Start of request."; ?>
Attempts:
2 left
💡 Hint
Think about when the shutdown function runs in relation to the main script.
✗ Incorrect
The main script prints "Start of request." first. The shutdown function runs after the script finishes, printing "End of request." so the combined output is "Start of request.End of request.".
🧠 Conceptual
intermediate1:30remaining
What happens first when a PHP request starts?
When a PHP request begins, which of these happens first?
Attempts:
2 left
💡 Hint
Think about what PHP must do before running your code.
✗ Incorrect
PHP first reads the script and compiles it into opcodes before executing any code or sending output.
❓ Predict Output
advanced2:00remaining
What error does this PHP code produce?
This PHP script tries to use a variable after the request ends. What error will it produce?
PHP
<?php register_shutdown_function(function() use (&$var) { echo $var; }); $var = "Hello"; ?>
Attempts:
2 left
💡 Hint
Variables used with 'use' in shutdown functions keep their value.
✗ Incorrect
The shutdown function captures $var by reference before the script ends, so it can output "Hello" without error.
🧠 Conceptual
advanced1:30remaining
Which PHP event marks the end of a request?
Which of these best describes when a PHP request ends?
Attempts:
2 left
💡 Hint
Think about what happens after your PHP code runs.
✗ Incorrect
A PHP request ends after the script finishes running and all output is sent to the client.
🔧 Debug
expert2:30remaining
Why does this PHP script output only 'Start' and not 'End'?
This PHP script tries to print 'End' at the end of the request but it doesn't appear. Why?
PHP
<?php register_shutdown_function(function() { echo "End"; }); exit("Start"); ?>
Attempts:
2 left
💡 Hint
Think about how exit() works with shutdown functions.
✗ Incorrect
exit() outputs 'Start' and then triggers shutdown functions, so 'End' is printed after 'Start'. The output is 'StartEnd'. If 'End' is missing, it may be due to output buffering or environment.