Fix all this PHP code: What’s wrong with the flowing function body ? function my
ID: 671125 • Letter: F
Question
Fix all this PHP code:
What’s wrong with the flowing function body ?
function my_function ( $x, $y, $z )
{
echo $x . $y . $z
}
What’s wrong with the flowing function definition?
Hint – there are two mistakes in this function. What are they?
function my_function ( x, y, z )
{
echo $x . $y . $z
}
What’s wrong with the flowing function definition?
function my function ( $x )
{
echo $x;
}
What’s wrong with the flowing function definition default argument?
Hint – $x is a default argument. So what’s wrong with the function argument code?
function my_function ( $x = )
{
$x = $x + 1;
echo $x
}
What’s wrong with the flowing function body?
function my_function ( $a )
{
$size_of_a = strlen( a );
echo $size_of_a;
}
What’s wrong with the flowing function body?
function my_function ( $a )
{
$size_of_a = ($a) strlen;
echo $size_of_a;
}
Explanation / Answer
What’s wrong with the flowing function body?
function my_function ( $x, $y, $z )
{
echo $x . $y . $z //double codes and semicolon is missed here.
}
The modified code:
function my_function ( $x, $y, $z )
{
echo "$x . $y . $z";
}
What’s wrong with the flowing function definition?
Hint – there are two mistakes in this function. What are they?
function my_function ( x, y, z ) //ampersand symbol($) is missed here
{
echo $x . $y . $z //double codes and semicolon is missed here.
}
The modified code:
function my_function ( $x, $y, $z )
{
echo "$x . $y . $z";
}
What’s wrong with the flowing function definition?
function my function ( $x ) //naming convention of function is incorrect.
{
echo $x; //double codes is missed
}
The modified code:
function my_function ( $x )
{
echo "$x";
}
What’s wrong with the flowing function definition default argument?
Hint – $x is a default argument. So what’s wrong with the function argument code?
function my_function ( $x = ) //Equal symbol is not required while passing the parameter.
{
$x = $x + 1;
echo $x //double codes and semicolon is missed here.
}
The modified code:
function my_function ( $x )
{
$x = $x + 1;
echo “$x”;
}
What’s wrong with the flowing function body?
function my_function ( $a )
{
$size_of_a = strlen( a );
echo $size_of_a; //double codes is missed here.
}
The modified code:
function my_function ( $a )
{
$size_of_a = strlen( $a );
echo “$size_of_a”;
}
What’s wrong with the flowing function body?
function my_function ( $a )
{
$size_of_a = ($a) strlen; //syntax error
echo $size_of_a; //double codes is missed here.
}
The modified code:
function my_function ( $a )
{
$size_of_a = strlen($a);
echo “$size_of_a”;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.