Step 1: Understand parameter types and argument passing
The function expects floats. PHP will convert integer 3 to float 3.0 automatically.
Step 2: Calculate the multiplication
3.0 * 4.5 = 13.5, so the function returns 13.5.
Final Answer:
13.5 -> Option A
Quick Check:
3 * 4.5 = 13.5 [OK]
Hint: PHP auto-converts int to float if declared [OK]
Common Mistakes:
Expecting TypeError for int passed to float
Calculating wrong multiplication
Confusing output with integer result
4. Identify the error in this PHP function declaration:
function greet(string name) {
return "Hello, $name!";
}
medium
A. Wrong type declaration keyword
B. Function must return int
C. Missing $ before parameter name
D. No error, code is correct
Solution
Step 1: Check parameter syntax
In PHP, parameter names must start with a $ sign, so string name is incorrect.
Step 2: Identify the correct syntax
The correct syntax is string $name with $ before the parameter name.
Final Answer:
Missing $ before parameter name -> Option C
Quick Check:
Parameter names need $ [OK]
Hint: Parameter names always start with $ in PHP [OK]
Common Mistakes:
Omitting $ before parameter name
Confusing type declaration with variable name
Assuming no $ needed in function parameters
5. Given this function:
function process(array $data, int $limit = 10) {
return array_slice($data, 0, $limit);
}
Which call will cause a TypeError?
hard
A. process([1, 2, 3], 2)
B. process('not an array', 5)
C. process([1, 2, 3])
D. process([1, 2, 3], 0)
Solution
Step 1: Analyze parameter types and defaults
The first parameter must be an array; the second is an int with default 10.
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.
Final Answer:
process('not an array', 5) causes TypeError -> Option B
Quick Check:
First param must be array, string causes error [OK]
Hint: 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
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.