PHP default argument function call PHP default argument function call php php

PHP default argument function call


Well, the short answer is that there is no better way to do it, to my knowledge. You can, however, make it look somewhat neater by using ternary operators.

function func3_name(arg1,arg2=null,etc...) {  arg2 = (arg2==null ? time() : arg2);}


Connor is 100% correct; however, as of PHP 7, you can now use the null coalesce operator.

i.e.

$arg2 = $arg2 ?? time();

Just a shorter, arguably cleaner, way to write it.