Bird
0
0

Identify the error in this PHP function declaration:

medium📝 Debug Q14 of 15
PHP - Functions
Identify the error in this PHP function declaration:
function setName(?string name) {
    echo $name;
}
AMissing dollar sign ($) before parameter name.
BNullable types cannot be used with strings.
CFunction must return a value.
DParameter cannot be nullable without default value.
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter syntax

    In PHP, all variable names must start with a dollar sign $. The parameter name is missing $.
  2. Step 2: Validate nullable type usage

    Nullable types like ?string are valid. The function does not require a return value. Parameters can be nullable without default values.
  3. Final Answer:

    Missing dollar sign ($) before parameter name. -> Option A
  4. Quick Check:

    Parameter variables need $ prefix [OK]
Quick Trick: Always prefix parameter names with $ in PHP functions [OK]
Common Mistakes:
  • Omitting $ in parameter names
  • Thinking nullable types need default values
  • Expecting functions must return values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes