Pure Function
A pure function is a function with no side effects. It adheres to two fundamental principles:
- Determinism: for the same input, a pure function will always return the same output. There are no hidden dependencies or side effects that could change the result.
- No side-effect: a pure function does not modify any external state or data. It does not change variables outside its scope, write to a database, modify a file, or perform any action that affects the world outside the function.
A function that is not pure is an impure function.
This notion applies to functions, methods, native and custom functions, closures and arrow functions.
<?php
function add(int $a, int $b): int {
return $a + $b;
}
?>