Lesson content
Read, practise, then check your understanding
Functions have local scope, defaults, variadic parameters, named arguments, callbacks, and declared parameter/return types. Values use copy-on-write; reference parameters should be rare and explicit.
Practical example
<?php
declare(strict_types=1);
function total(float ...$values): float { return array_sum($values); }
function factorial(int $n): int { if ($n < 0) throw new InvalidArgumentException(); return $n <= 1 ? 1 : $n * factorial($n - 1); }
Named arguments make parameter names part of the public API. Closures capture through use; arrow functions capture by value automatically. Recursion requires a base case and can exhaust resources. Keep side effects and failure contracts visible.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.