PHP - Basics and Execution ModelWhich PHP code snippet correctly checks if the script is running in CLI mode?Aif (php_sapi_name() == 'web') { echo 'CLI mode'; }Bif ($_SERVER['REQUEST_METHOD'] == 'CLI') { echo 'CLI mode'; }Cif (php_sapi_name() == 'cli') { echo 'CLI mode'; }Dif (isset($_GET['cli'])) { echo 'CLI mode'; }Check Answer
Step-by-Step SolutionSolution:Step 1: Identify correct function for checking CLIphp_sapi_name() returns the interface type; 'cli' means command line interface.Step 2: Validate condition logicif (php_sapi_name() == 'cli') { echo 'CLI mode'; } correctly compares php_sapi_name() to 'cli' to detect CLI mode.Final Answer:if (php_sapi_name() == 'cli') { echo 'CLI mode'; } -> Option CQuick Check:php_sapi_name() == 'cli' detects CLI [OK]Quick Trick: Use php_sapi_name() == 'cli' to detect CLI [OK]Common Mistakes:Using $_SERVER['REQUEST_METHOD'] for CLI detectionChecking for 'web' instead of 'cli'Relying on GET parameters to detect CLI
Master "Basics and Execution Model" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Arrays - Indexed array creation - Quiz 6medium Conditional Statements - Ternary operator - Quiz 15hard Conditional Statements - Elseif ladder execution - Quiz 2easy Conditional Statements - If statement execution flow - Quiz 8hard Operators - String concatenation operator - Quiz 1easy Operators - Logical operators - Quiz 6medium Operators - Assignment and compound assignment - Quiz 5medium Output and String Handling - Printf and sprintf formatting - Quiz 2easy PHP Basics and Execution Model - First PHP program (Hello World) - Quiz 3easy Variables and Data Types - PHP dynamic typing behavior - Quiz 9hard