CKTIS / PHP
Functions and parameters
Parameters receive values by default.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
function add(int &$sum, int $delta = 1): int { return $sum += $delta; }Parameters receive values by default. A parameter declared with & binds a caller variable so changes are visible after return. Defaults apply to omitted arguments. Named arguments can select parameters out of order, making parameter names part of the calling interface.
function add(int &$sum,int $delta=1):int {return $sum+=$delta;}
$total=3; $first=add($total); $next=add(delta:2,sum:$total);echo json_encode([$first,$next,$total]);
[4,6,6]
Examples
<?php
function add(int &$sum,int $delta=1):int {return $sum+=$delta;}
$total=3; $first=add($total); $next=add(delta:2,sum:$total);echo json_encode([$first,$next,$total]);
Result
[4,6,6]