Bird
0
0

Given this function:

hard📝 Application Q15 of 15
PHP - Functions
Given this function:
function process(array $data, int $limit = 10) {
    return array_slice($data, 0, $limit);
}

Which call will cause a TypeError?
Aprocess([1, 2, 3], 2)
Bprocess('not an array', 5)
Cprocess([1, 2, 3])
Dprocess([1, 2, 3], 0)
Step-by-Step Solution
Solution:
  1. Step 1: Analyze parameter types and defaults

    The first parameter must be an array; the second is an int with default 10.
  2. Step 2: Check each call

    process([1, 2, 3], 2) passes array and int correctly. process('not an array', 5) passes a string instead of array, causing TypeError. Options A, B, and C pass valid types.
  3. Final Answer:

    process('not an array', 5) causes TypeError -> Option B
  4. Quick Check:

    First param must be array, string causes error [OK]
Quick Trick: Check argument types match declared parameter types [OK]
Common Mistakes:
  • Passing wrong type for array parameter
  • Assuming default values fix type errors
  • Ignoring parameter order and types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes