Bird
0
0

What will be the output when running this PHP script via CLI?

medium📝 Predict Output Q13 of 15
PHP - Basics and Execution Model
What will be the output when running this PHP script via CLI?
if (php_sapi_name() == 'cli') {
    echo "Running in CLI";
} else {
    echo "Running on Web Server";
}
ARunning in CLI
BRunning on Web Server
CNo output
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Check php_sapi_name() value in CLI

    When run in CLI, php_sapi_name() returns 'cli'.
  2. Step 2: Evaluate the if condition

    The condition is true, so it echoes "Running in CLI".
  3. Final Answer:

    Running in CLI -> Option A
  4. Quick Check:

    php_sapi_name() == 'cli' true in CLI [OK]
Quick Trick: php_sapi_name() returns 'cli' in terminal [OK]
Common Mistakes:
  • Assuming it prints 'Running on Web Server' in CLI
  • Expecting no output
  • Confusing syntax error with runtime output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes