What is the output of the following code?
function ratio ($x1 = 10, $x2)
{
if (isset ($x2)) {
return $x2 / $x1;
}
}
echo ratio (0);
Suggested Answer: D
Get Premium 200-710 Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
21 comments · newest first
AL
Aleshia
2 months ago
I’m confused. Could it be F? Nothing happens?
OR
Orville
2 months ago
I feel like it’s definitely D. The function needs $x2.
LO
Lore
2 months ago
But $x2 is missing, so it should warn us.
EM
Emilio
3 months ago
I’m leaning towards A. It returns 0 since $x1 is 10.
BR
Broderick
3 months ago
Yeah, I agree. It will throw a warning.
CR
Craig
3 months ago
I think the answer is D. $x2 is not set.
SU
Susana
3 months ago
I vote for D too. It’s clear $x2 is missing.
RE
Rebbecca
3 months ago
I feel like it’s a warning, but I’m not sure if it’s D or C.
DA
Darell
4 months ago
But isn’t D more accurate? It warns about $x2.
BI
Billy
4 months ago
I’m leaning towards A. It returns 0 since $x2 is 0.
GE
Gerald
4 months ago
Yeah, I agree with D. The function needs $x2.
JE
Jeffrey
4 months ago
I think it should be D. $x2 is not set.
JU
Justa
4 months ago
I disagree, it should just return nothing.
KR
Kristofer
4 months ago
Wait, why is $x1 even a factor here?
HO
Hoa
5 months ago
Definitely not an integer overflow error!
CL
Clay
6 months ago
I think it's a warning because $x2 isn't set.
TI
Tina
6 months ago
The output will be 0.
LU
Luke
7 months ago
I’m leaning towards option D, but I’m not completely confident since I can’t recall how PHP handles default values in this context.
MA
Marti
7 months ago
This reminds me of a practice question where a missing parameter caused a warning. I feel like that might happen here too.
SH
Shad
7 months ago
I remember something about default parameters, but I’m confused if $x2 being unset will cause a warning or not.
UL
Ula
7 months ago
I think the function will return 0 since $x2 is passed as 0, but I'm not entirely sure about the default value of $x1.