PaulB
Well-known member
- Affected version
- 2.2.3
We were investigating what types
createDomElements:
createDomElement:
If
\XF\Mvc\Reply#getMessage()
can return, since it's not documented in the class itself, and PhpStorm likes to assume that it will always be a string. In first-party code, it's used exclusively by the various implementations of \XF\Mvc\Renderer#renderRedirect
. However, there are discrepancies between how different implementations handle it; XML's in particular appears to be broken.- Html: ignores the value
- Json: expects
string|\Stringable|\JsonSerializable
--can technically handle other types, but the output will be something other than a string - Raw: ignores the value
- Rss: extends Xml, doesn't override renderRedirect
- Xml:
string
, despite attempting to use aPhrase
if the value isn't truthy
PHP:
\XF\Util\Xml::createDomElements($rootNode, [
'status' => $type,
'url' => $url,
'message' => (!$message ? \XF::phrase('redirect_changes_saved_successfully') : $message)
]);
createDomElements:
PHP:
self::createDomElement($document, 'message', $message);
createDomElement:
PHP:
$e = $document->createElement('message');
if (is_scalar($message))
{
$e->appendChild($document->createTextNode($message));
}
else if ($message instanceof \DOMNode)
{
$e->appendChild($value);
}
return $e;
If
$message
is a truthy scalar, this code will work correctly; however, if it's a Phrase, it will break, resulting in an empty <message />
node.