Quantcast
Channel: User bdsl - Stack Overflow
Viewing all articles
Browse latest Browse all 38

Answer by bdsl for Can a function be passed as a default parameter somehow?

$
0
0

No, you can't call a function to provide a default argument value. As the docs put it, "The default value must be a constant expression, not (for example) a variable, a class member or a function call."

I think an idomatic way to write the function you want would be with a default null value, and a docblock to explain the meaning of null, i.e.:

/** * @param ?string $at reference creation time in Y-m-d H:i:s format, or null for now. */ public function insert_user_to_user_reference(    string $referrer_id,    string $referee_id,    ?string $at = null ) {     if ($at === null) {         $at = date('Y-m-d H:i:s');     }     //some code here ... }

Viewing all articles
Browse latest Browse all 38

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>