Send messages to multiple passed recipients or a default recipient I have a function that accepts false as a default value but can be passed an array.

protected function sendMessages ($recipients = false) {

    //cast to an array
    $recipients = is_array($recipients) ? $recipients : [$recipients];

    // if no recipients are passed get email from current object (default)
    if (isset($recipients[0]) &amp;&amp; $recipients[0] === false) {
        array_pop($recipients);
        array_push($recipients, 'email' =&gt; $this-&gt;author-&gt;email);
    }

    foreach ($recipients as $recipient) {
        //some logic.
    }
}


The whole, check if the first element is false, and if so swap it out seems a little convoluted / backwards to me. But I'm not sure of a cleaner method. The default value could be changed but is needed so that older calls to the method that specify no parameters don't choke.
protected function sendMessages (array $recipients = []) {

    // if no recipients are passed get email from current object (default)
    if ( ! $recipients) {
        array_push($recipients, 'email' =&gt; $this-&gt;author-&gt;email);
    }

    foreach ($recipients as $recipient) {
        //some logic.
    }
}


Assuming you can change the default value, an empty array evaluates as false: https://3v4l.org/Onpcv (alternatively if you don’t like using it like that, do a check on the count, or empty etc)