Bird
0
0

Consider this PHP code snippet:

medium📝 Debug Q14 of 15
PHP - Type Handling
Consider this PHP code snippet:
$value = true;
if (typeof($value) === 'boolean') {
echo 'Boolean type';
} else {
echo 'Not boolean';
}

What is the problem with this code?
Atypeof is not a valid PHP function
BComparison operator === cannot be used with strings
CBoolean values cannot be checked with typeof
DThe variable $value is not defined
Step-by-Step Solution
Solution:
  1. Step 1: Check if typeof is a PHP function

    PHP does not have a built-in typeof() function; it uses gettype() instead.
  2. Step 2: Analyze the impact of using typeof()

    Using typeof() causes a fatal error because the function does not exist.
  3. Final Answer:

    typeof is not a valid PHP function -> Option A
  4. Quick Check:

    typeof() invalid in PHP [OK]
Quick Trick: Use gettype(), not typeof(), in PHP [OK]
Common Mistakes:
  • Assuming typeof() exists in PHP like in JavaScript
  • Thinking === cannot compare strings
  • Ignoring variable initialization

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes