Search code examples
phpdocumentation

Is there a PHP Doc syntax for "function modifies argument passed by reference"?


When writing a PHP doc for a function, if the function returns a value you'd write something like

@return array $someArray An array of formatted dates

But let's say that my function doesn't return a value but rather it modifies the original value that is passed as a reference something like:

   function formatDates(&$input_arr){
        /**
         * Formats an array of dates
         * @param array $input_arr An array of raw dates
         */
        array_walk_recursive($input_arr, 'formatDateFunction');
    }

This function modifies the input array.

I know it's obvious with the & in front of the parameter but return values are pretty obvious with return in front of them too, so I feel like there may be a standard for this?

Currently, I just mention it in the function description like:

        /**
         * Formats an array of dates, modifies original array

Is there a commonly used way of stating that a function modifies the input value in the PHP docs? Or is it just normally left as implied?


Solution

  • Like so

    * @param array &$array modified parameter array of dates