Bird
0
0

Which of the following function declarations correctly enforces a parameter to be a float in PHP?

easy📝 Syntax Q3 of 15
PHP - Functions
Which of the following function declarations correctly enforces a parameter to be a float in PHP?
Afunction calc(float $num) {}
Bfunction calc(Float $num) {}
Cfunction calc(number $num) {}
Dfunction calc(decimal $num) {}
Step-by-Step Solution
Solution:
  1. Step 1: Check PHP type names

    PHP uses lowercase 'float' as a scalar type declaration.
  2. Step 2: Validate each option

    'Float' with uppercase is invalid, 'number' and 'decimal' are not PHP types.
  3. Final Answer:

    function calc(float $num) {} -> Option A
  4. Quick Check:

    Correct float type declaration = float [OK]
Quick Trick: Use lowercase scalar types like int, float, string [OK]
Common Mistakes:
  • Capitalizing scalar types incorrectly
  • Using non-existent types like 'number' or 'decimal'
  • Confusing type names with variable names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes