Web Designing MCQs

20 Best MCQ Questions on PHP Functions

Pinterest LinkedIn Tumblr
Here are the collections of the 20 best MCQ questions on PHP functions includes multiple-choice questions on the fundamentals of PHP functions. It includes MCQ questions on creating a function with passing arguments by value and reference, returning values from a function, recursive functions, function arguments, variable functions, anonymous functions, and arrow functions.

Read Also: Multiple Choice Questions On PHP Basis

1. In PHP valid function name starts with a ……………………. followed by any number of letters, numbers, or underscores.
i. numbers
ii. letters
iii. underscores
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii

2.State whether the following statements about PHP functions are true.
i. All the functions in PHP have a global scope.
ii) PHP supports function overloading.
iii) It is not possible to undefine or redefine previously declared functions.
A) i-True, ii-False, iii-False
B) i-True, ii-True, iii-True
C) i-True, ii-False, iii-True
D) i-True, ii-True, iii-False

3. What will be the output of the following code?

<?php pow(0,0); ?>

A) 0
B) 1
C) inf
D) NAN

4.Writing 2**3; will return the following result in PHP.
A) 5
B) 6
C) 8
D) NAN

5.Which of the following is/are the mathematical functions used in PHP.
i. exp
ii. pow
iii. log
iv. log5()
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) All i, ii, iii and iv

6. By default, function arguments are passed by …….
A) value
B) reference
C) argument value
D) Both A and C

7.While passing function arguments by reference, we will prepend …………… to the argument name.
A) dollor($)
B) ampersand(&)
C) hash(#)
D) dot(.)

8.To return a reference from a function, we will use the reference operator (&) in …..
i) function declaration
ii) assigning the returned values
A) i only
B) ii only
C) Both i and ii
D) None of the above

9.What will be the output of the following code.

<?php
function sum($a, $b): float {
    return $a + $b;
}
var_dump(sum(1, 2));
?>

A) 3
B) float(3)
C) NAN
D) Generates Error

10.A call to ………….. will show which extensions are loaded into PHP.
i) phpinfo()
ii) get_loaded_extensions()
iii) loaded_extensions()
A) i and ii
B) i and iii
C) ii and iii
D) All i, ii and iii

11.What will be the output of the following code.

<?php
$language = function($name)
{
    printf("%s Programming", $name);
};

$language('PHP');
?>

A) PHP programming
B) Programming
C) PHP
D) Generates Error

12.PHP5 introduced a new feature known as ………….. which gives you the ability to force parameters to be objects of a certain class or to be arrays.
A) parameters hinting
B) objects hinting
C) type hinting
D) hinting

13.State whether the following statements on return statements are True or False.
i) If return() is called from within the global scope, the script execution is terminated.
ii) A function can also return multiple values without using an array.
iii) If the return() is omitted the value NULL will be returned.
A) i-True, ii-False, iii-False
B) i-True, ii-True, iii-True
C) i-True, ii-False, iii-True
D) i-True, ii-True, iii-False

14. What will be the output of the following PHP code.

<?php
function display($a)
{
    if ($a < 20) {
        echo "$a\n";
        display($a + 1);
    }
}
echo display(19);
?>

A) 20
B) 19 20
C) Null
D) 19

15.State whether the following statements on return type declarations are True.
i. Return type declarations specify the type of value that will be returned from a function.
ii. When overriding a parent method, the child’s method must match any type of declaration on the parent.
A) i only
B) ii only
C) Both i and ii
D) None of the above

16.Which of the following statements are True about the variable functions on PHP.
i. PHP will look for a function with the same name as whatever the variable values to it.
ii. Variable functions won’t work with language constructs.
iii. Object methods can not be called with the variable functions.
A) i-True, ii-False, iii-False
B) i-True, ii-True, iii-True
C) i-True, ii-False, iii-True
D) i-True, ii-True, iii-False

17.What will be the output of the following PHP code.

<?php
$z = 1;
$fn = fn($x) => fn($y) => $x * $y + $z;
var_export($fn(3)(5));
?>

A) 16
B) 15
C) Null
D) Generates error

18.State Whether the following statements are True or False.
i. Anonymous functions are also known as closures.
ii. Closures can also be used as the value of variables
iii. Closures can not inherit variables from the parent scope.
A) i-True, ii-False, iii-False
B) i-True, ii-True, iii-True
C) i-True, ii-False, iii-True
D) i-True, ii-True, iii-False

19.Arrow functions support the same features as …………. except that using variables from the parent scope is always automatic.
A) Variable functions
B) Static functions
C) Anonymous functions
D) Both A and C

20.What will the output of the following code.

<?php
$x = 1;
$fn = fn(&$x) => $x++;
$fn($x);
var_export($x);
?>

A) 1
B) 2
C) 0
D) Null

Answers:

  1. B) ii and iii only
  2. C) i-True, ii-False, iii-True
  3. B) 1
  4. C) 8
  5. A) i, ii and iii only
  6. A) value
  7. B) ampersand(&)
  8. C) Both i and ii
  9. B) float(3)
  10. A) i and ii
  11. A) PHP programming
  12. C) type hinting
  13. C) i-True, ii-False, iii-True
  14. D) 19
  15. C) Both i and ii
  16. D) i-True, ii-True, iii-False
  17. A) 16
  18. D) i-True, ii-True, iii-False
  19. C) Anonymous functions
  20. B) 2

Read Next: Top 20 MCQ Questions on Arrays in PHP

Please follow and like us:
RSS
Follow by Email
X (Twitter)
Visit Us
Follow Me
YouTube
YouTube
LinkedIn
linkedIn | 20 Best MCQ Questions on PHP Functions
Share

Author

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

Write A Comment

RSS
Follow by Email
X (Twitter)
Visit Us
Follow Me
YouTube
YouTube
LinkedIn
Share