Bifalgorithm post · Computer science one · Optional & Default Parameters

What happens when optional PHP function parameters are omitted?

What happens when optional PHP function parameters are omitted? (Computer science one · Optional & Default Parameters) — "Parameters in PHP functions are optio…

Ideas in this flowchart

  • Optional parameters in PHP functions are treated as null when omitted.
  • A function can be invoked without providing some parameters.
  • Each omitted parameter receives the value null.
  • In distance formula calculations, null values are treated as zero.
  • Example: getDistance(10.0, 20.0) provides only two arguments.
  • $x1 and $y1 take the values 10 and 20.
  • $x2 and $y2 become null and are treated as zero in the calculation.
  • Example: getDistance() provides no arguments.
  • All four parameters become null and are treated as zero in the calculation.
Feed/

What happens when optional PHP function parameters are omitted?

No cover

Channel

Computer science one

1 page

"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)."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.