Multiple choice php

Under what circumstance is it impossible to assign a default value to a parameter while declaring a function?

  1. When the parameter is Boolean

  2. When the function is being declared as a member of a class

  3. When the parameter is being declared as passed by reference

  4. When the function contains only one parameter

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Default values for function parameters (using '= value') are syntactically valid in C++ for primitive types (like Boolean) and class methods. However, they generally cannot be used for parameters passed by reference unless the reference is to a const type (e.g., 'const int&'). As the option implies a non-const reference (standard modifiable reference), this is the circumstance where a default argument is typically invalid or nonsensical.

AI explanation

When a parameter is declared to be passed by reference, it cannot be given a default value, because a reference must be bound to an actual existing variable at call time, not a literal or temporary default. This is why languages like PHP and C++ restrict default values on reference parameters. The other options (Boolean type, member of a class, single-parameter function) do not create this restriction.