Concept
What happens when optional PHP function parameters are omitted?
ComputerScienceOne / Optional & Default Parameters
"Parameters in PHP functions are optional. You can invoke a function without providing a subset of parameters. However, if a parameter is not provided, PHP will treat the parameter as null. If we invoked the getDistance() function with only two parameters: getDistance(10.0, 20.0); then inside the function, $x1 and $y1 would take on the values 10 and 20, but $x2 and $y2 would be null. When used in the distance formula calculations, both would be treated as zero. If we had invoked the function with no arguments, getDistance(); then all four parameters would be treated as null (and thus zero in the calculations)."
Related Ideas
- How do omitted arguments match parameters in PHP functions?ComputerScienceOne · Function Pointers
- How do optional and default function parameters work in PHP?ComputerScienceOne · Generalized Rounding
- How does PHP handle undefined variables, null values, and constants?ComputerScienceOne · Using Variables
- What are the key features of functions in PHP?ComputerScienceOne · Declaring Functions
- How can PHP default values let a constructor accept different numbers of parameters?ComputerScienceOne · Usage
- How do you call a function in PHP?ComputerScienceOne · Calling Functions
- How do you declare functions and specify their return values in PHP?ComputerScienceOne · Declaring Functions
- What happens when a PHP function does not return a value?ComputerScienceOne · Calling Functions