0
0
PHPprogramming~20 mins

How PHP executes on the server - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP Server Execution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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();
?>
A321
B111
C123
DSyntax Error
Attempts:
2 left
💡 Hint
Static variables inside functions keep their value between calls.
🧠 Conceptual
intermediate
1:30remaining
PHP Server Execution Flow
Which step correctly describes what happens first when a PHP file is requested by a browser?
AThe browser executes the PHP code directly.
BThe PHP code is compiled into a binary executable on the client.
CThe server sends the PHP code as plain text to the browser.
DThe PHP interpreter parses and executes the PHP code on the server.
Attempts:
2 left
💡 Hint
Remember where PHP code runs: server or client?
🔧 Debug
advanced
2: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.";
}
?>
AOutputs: Number is five.
BOutputs: Number is not five.
CSyntax Error due to assignment in if condition.
DRuntime Error: Undefined variable.
Attempts:
2 left
💡 Hint
Check the difference between '=' and '==' in conditions.
📝 Syntax
advanced
1: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");
?>
A
&lt;?php
function greet($name) {
    echo "Hello, $name!";
}
greet("Alice"
?&gt;
B
&lt;?php
function greet($name) {
    echo "Hello, $name!";
}
greet("Alice");
?&gt;
C
&lt;?php
function greet($name) {
    echo "Hello, $name!";
}
greet("Alice");
D
&gt;?
;)"ecilA"(teerg
}
;"!eman$ ,olleH" ohce    
{ )eman$(teerg noitcnuf
php?&lt;
Attempts:
2 left
💡 Hint
Look for missing parentheses or semicolons.
🚀 Application
expert
2: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();
?>
AStart-End
BEnd
CStart
DNo output
Attempts:
2 left
💡 Hint
ob_clean() clears the output buffer before sending it.