XF 2.0 return array() or return null ?


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

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

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
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.
/* @return null|array */
Or simply just do as you've done in your example above and return an empty array.
Reactions: LPH