Challenge - 5 Problems
PHP Server Execution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
PHP Script Execution Output
What is the output of this PHP code when executed on a server?
PHP
<?php function test() { static $count = 0; $count++; return $count; } echo test(); echo test(); echo test(); ?>
Attempts:
2 left
💡 Hint
Static variables inside functions keep their value between calls.
✗ Incorrect
The static variable $count inside the function test() retains its value between calls, so it increments each time test() is called, producing 1, then 2, then 3, output as '123'.
🧠 Conceptual
intermediate1:30remaining
PHP Server Execution Flow
Which step correctly describes what happens first when a PHP file is requested by a browser?
Attempts:
2 left
💡 Hint
Remember where PHP code runs: server or client?
✗ Incorrect
PHP code runs on the server. When a PHP file is requested, the server uses the PHP interpreter to parse and execute the code, then sends the resulting output (usually HTML) to the browser.
🔧 Debug
advanced2:00remaining
Identify the Error in PHP Execution
What error will this PHP code produce when executed on the server?
PHP
<?php $number = 10; if ($number = 5) { echo "Number is five."; } else { echo "Number is not five."; } ?>
Attempts:
2 left
💡 Hint
Check the difference between '=' and '==' in conditions.
✗ Incorrect
The if condition uses '=' which assigns 5 to $number and returns true, so the if block runs and outputs 'Number is five.'. This is a common mistake where '==' (comparison) was intended.
📝 Syntax
advanced1:30remaining
PHP Syntax Error Identification
Which option contains a syntax error that will prevent PHP from executing the script?
PHP
<?php function greet($name) { echo "Hello, $name!"; } greet("Alice"); ?>
Attempts:
2 left
💡 Hint
Look for missing parentheses or semicolons.
✗ Incorrect
Option A is missing the closing parenthesis in the greet function call, causing a syntax error and preventing execution.
🚀 Application
expert2:30remaining
PHP Output Buffering Behavior
What will be the output of this PHP code when executed on the server?
PHP
<?php ob_start(); echo "Start-"; ob_clean(); echo "End"; ob_end_flush(); ?>
Attempts:
2 left
💡 Hint
ob_clean() clears the output buffer before sending it.
✗ Incorrect
The output buffer starts and 'Start-' is echoed but then ob_clean() clears the buffer, so 'Start-' is removed. Then 'End' is echoed and finally ob_end_flush() sends the buffer content, which is 'End'.