Function Argument Typing
NoteThis feature is a work in progress, considering the new type-related features in PHP 8.
You can declare the type of each argument passed to a function. Calls that don’t match these types will fail at runtime.
To declare a type, append a type token to the argument with a colon :
.
// Take a (n)umber and a (s)tring fun countItems($num:n, $itemName:s) { print('You have ' ~ $num ~ ' ' ~ $itemName) } countItems(3, 'tacos') //= 'You have 3 tacos' countItems('tacos', 3) // ✕ ERROR. Arguments are reversed.
Type Tokens
Token | Type |
---|---|
s |
string |
b |
boolean |
n |
number |
l |
list |
m |
map |
o |
object |
fn |
function |
any |
all types (same as no type at all) |
Return Types
TODOReturn types are still WIP