0

I have a function which returns something like the following structure:

array('form' => $form, 'options' => $options)

How to correctly format this return value in function comment?

My guess is:

@return array('form' => CForm, 'options' => array) ... comment ...

Any suggestions?

4

2 回答 2

1

当您必须返回一个奇怪的数组时,只需简单易懂地记录它。

这就是我将如何做到的。随意使用@return array,而不是mixed[]

<?php
/**
 * Method to do something
 *
 * @param Some_User_Class $user
 * @param string $blockUserId
 * @throws Some_Model_Relations_ErrorException
 * @return mixed[] see example
 * @example The returned array consists of this
 *  and that and might have foo and bar.
 *  so this makes me feel like the code should be refactored.
 */
public function unblockUser(Some_User_Class $user, $unblockUserId) {
}
于 2012-11-15T09:27:55.217 回答
0

也许有点矫枉过正,但您可以返回具有特定接口的对象,而不是常规数组。就像是:

/**
 * @return ReturnObject
 */
public function yourMethod()
{
    return new ReturnObjectImpl( $theForm, $theOptions );
}

interface ReturnObject
{
    public function getCForm();
    public function getOptions();
}

class ReturnObjectImpl
    implements ReturnObject
{
    protected $_form;
    protected $_options;

    public function __construct( CForm $form, array $options )
    {
        $this->_form = $form;
        $this->_options = $options;
    }

    public function getCForm()
    {
        return $this->_form;
    }

    public function getOptions()
    {
        return $this->_options;
    }
}
于 2012-11-15T08:37:21.587 回答