• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 return array() or return null ?

LPH

Well-known member
#1
In adding validate to posting externally, the following was added.

PHP:
/** @var \XF\Service\Thread\Replier $replier */
$replier = \XF::app()->service('XF:Thread\Replier', $thread);
$replier->setMessage($message);

if (!$replier->validate())
{
 return array();
}

$post = $replier->save();
XenForo developers used return; but PhpStorm wants an array. Is it better to use return array(); or return null; ?
 

Chris D

XenForo developer
Staff member
#2
Our validation methods tend not to actually return anything i.e. they're just void methods - they do their job, and they pop any errors into an $errors reference variable.

Presumably your method is returning the actual post data as an array. It should be possible to mix return types (if you have to) you'd just have to edit your PhpDoc comments to indicate that, e.g.
PHP:
/* @return null|array */
Or simply just do as you've done in your example above and return an empty array.