Fixed Template error: [E_WARNING] Uninitialized string offset 0 src/XF/Language.php:199

Affected version
XF2.2.5

Robru

Well-known member
Code:
Stack trace
#0 src/XF/Language.php(199): XF\Template\Templater->handleTemplateError(2, '[E_WARNING] Uni...', '/var/www/html/c...', 199)
#1 src/XF/Language.php(128): XF\Language->getEffectivePhraseName('', Array, Array)
#2 src/XF/Phrase.php(52): XF\Language->renderPhrase('', Array, 'html', Array)
#3 src/XF/Phrase.php(59): XF\Phrase->render()
#4 src/XF.php(1145): XF\Phrase->__toString()
#5 src/XF/Template/Templater.php(1178): XF::escapeString(Object(XF\Phrase), 'html')
#6 internal_data/code_cache/templates/l1/s0/admin/log_spam_trigger_list.php(30): XF\Template\Templater->escape(Object(XF\Phrase))
#7 src/XF/Template/Templater.php(1628): XF\Template\Templater->{closure}(Object(xenMade\LAU\XF\Template\Templater), Array, NULL)
#8 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('log_spam_trigge...', Array)
#9 src/XF/Mvc/Renderer/Html.php(48): XF\Template\Template->render()
#10 src/XF/Mvc/Dispatcher.php(458): XF\Mvc\Renderer\Html->renderView('XF:Log\\SpamTrig...', 'admin:log_spam_...', Array)
#11 src/XF/Mvc/Dispatcher.php(440): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#12 src/XF/Mvc/Dispatcher.php(400): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#13 src/XF/Mvc/Dispatcher.php(58): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#14 src/XF/App.php(2337): XF\Mvc\Dispatcher->run()
#15 src/XF.php(488): XF\App->run()
#16 admin.php(13): XF::runApp('XF\\Admin\\App')
#17 {main}
Code:
Request state
array(4) {
  ["url"] => string(39) "/community/admin.php?logs/spam-trigger/"
  ["referrer"] => string(51) "https://www.caviaforum.nl/community/admin.php?logs/"
  ["_GET"] => array(1) {
    ["logs/spam-trigger/"] => string(0) ""
  }
  ["_POST"] => array(0) {
  }
}
 

Mike

XenForo developer
Staff member
This is potentially an error that we can (and should) prevent. However, it might be coming from something that we expect to be specified for the content type triggering the spam log entry. Specifically, it should be the last part of this line:

1621248557023.png

When you view the spam trigger list, do you see any "content" values that don't start with an upper case letter or might have an underscore in them?
 

Robru

Well-known member
This is potentially an error that we can (and should) prevent. However, it might be coming from something that we expect to be specified for the content type triggering the spam log entry. Specifically, it should be the last part of this line:

View attachment 252034

When you view the spam trigger list, do you see any "content" values that don't start with an upper case letter or might have an underscore in them?
The spam trigger currently contains two "content" values. I can't find out anything about it, but I will post them both below. Maybe the e-mail address in the second code? That contains an underscore.

Code:
Action: Moderated StopForumSpam matched (username: 44)
Generated by: Monika Tuesday at 8:03 PM Content: User
Request state
array(4) {
  ["url"] => string(28) "/community/register/register"
  ["referrer"] => string(48) "https://www.caviaforum.nl/community/tags/elkaar/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(15) {
    <snip>
}
Code:
Action: Moderated StopForumSpam matched (username: 147)
Generated by: jacqueline May 8, 2021 Content: User
Request state
array(4) {
  ["url"] => string(28) "/community/register/register"
  ["referrer"] => string(45) "https://www.caviaforum.nl/community/register/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(16) {
    <snip>
 
Last edited by a moderator:

Mike

XenForo developer
Staff member
I've snipped out some of the details -- they won't be relevant to this error.

Though interestingly, I'm not totally sure why either of those would generate this error. Did looking at the spam trigger list create a new instance of the error you mentioned in the first message?
 

Robru

Well-known member
No, the last spam trigger report was last Thursday. The notification of my first message will come back every day.

1621254215545.png
 

Mike

XenForo developer
Staff member
This error is coming from the "contact" entries I believe, rather than the user entries. That's actually a built in check as well.
 

Andy.N

Well-known member
Running PHP 8.0.6, I have errors generated each time I view an entry in the spam trigger log.
Seems like with PHP 8.0.6, viewing the spam trigger log will cause these warning.

Server error log
  • ErrorException: Template error: [E_WARNING] Uninitialized string offset 0
  • src/XF/Language.php:199
  • Generated by: Andy.N
  • 5/23/21 at 1:01 PM

Stack trace​

#0 src/XF/Language.php(199): XF\Template\Templater->handleTemplateError(2, '[E_WARNING] Uni...', '/home/nginx/dom...', 199)
#1 src/XF/Language.php(128): XF\Language->getEffectivePhraseName('', Array, Array)
#2 src/XF/Phrase.php(52): XF\Language->renderPhrase('', Array, 'html', Array)
#3 src/XF/Phrase.php(59): XF\Phrase->render()
#4 src/XF.php(1145): XF\Phrase->__toString()
#5 src/XF/Template/Templater.php(1178): XF::escapeString(Object(XF\Phrase), 'html')
#6 internal_data/code_cache/templates/l1/s0/admin/log_spam_trigger_view.php(21): XF\Template\Templater->escape(Object(XF\Phrase))
#7 src/XF/Template/Templater.php(1628): XF\Template\Templater->{closure}(Object(SV\StandardLib\XF\Template\Templater), Array, NULL)
#8 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('log_spam_trigge...', Array)
#9 src/XF/Mvc/Renderer/Json.php(84): XF\Template\Template->render()
#10 src/XF/Mvc/Renderer/Json.php(68): XF\Mvc\Renderer\Json->renderHtmlFallback('XF:Log\\SpamTrig...', 'admin:log_spam_...', Array)
#11 src/XF/Mvc/Dispatcher.php(458): XF\Mvc\Renderer\Json->renderView('XF:Log\\SpamTrig...', 'admin:log_spam_...', Array)
#12 src/XF/Mvc/Dispatcher.php(440): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Json), Object(XF\Mvc\Reply\View))
#13 src/XF/Mvc/Dispatcher.php(400): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Json), Object(XF\Mvc\Reply\View))
#14 src/XF/Mvc/Dispatcher.php(58): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'json')
#15 src/XF/App.php(2337): XF\Mvc\Dispatcher->run()
#16 src/XF.php(488): XF\App->run()
#17 admin.php(13): XF::runApp('XF\\Admin\\App')
#18 {main}

Request state​

array(4) {
["url"] => string(177) "/admin.php?logs/spam-trigger/19979/&_xfRequestUri=%2Fadmin.php%3Flogs%2Fspam-trigger%2F&_xfWithData=1&_xfToken=1621789184%2Cd7a7c82d11a25e83fba7a545cb0f1f61&_xfResponseType=json"
["referrer"] => string(49) "https://domain.com/admin.php?logs/spam-trigger/"
["_GET"] => array(5) {
["logs/spam-trigger/19979/"] => string(0) ""
["_xfRequestUri"] => string(29) "/admin.php?logs/spam-trigger/"
["_xfWithData"] => string(1) "1"
["_xfToken"] => string(43) "1621789184,d7a7c82d11a25e83fba7a545cb0f1f61"
["_xfResponseType"] => string(4) "json"
}
["_POST"] => array(0) {
}
}
 

Mike

XenForo developer
Staff member
I don't believe this is PHP 8 related, though it is related to a somewhat recent change. There was a bug here prior to this but it wasn't really obvious.

These errors can simply be disregarded for now.
 

Robru

Well-known member
Because the spam trigger messages disappear over time, this problem is no longer visible to me and I no longer see any errors.
 

Kirby

Well-known member
I just wanted to submit the same issue ...

Code:
ErrorException: Template error: [E_WARNING] Uninitialized string offset 0 src/XF/Language.php:199
Generiert durch: Kirby 18. Juni 2021 um 11:57 Uhr
Stracktrace
#0 src/XF/Language.php(199): XF\Template\Templater->handleTemplateError(2, '[E_WARNING] Uni...', '<redacted-path>...', 199)
#1 src/XF/Language.php(128): XF\Language->getEffectivePhraseName('', Array, Array)
#2 src/XF/Phrase.php(52): XF\Language->renderPhrase('', Array, 'html', Array)
#3 src/XF/Phrase.php(59): XF\Phrase->render()
#4 src/XF.php(1145): XF\Phrase->__toString()
#5 src/XF/Template/Templater.php(1178): XF::escapeString(Object(XF\Phrase), 'html')
#6 <redacted-code-cache>/templates/l3/s0/admin/log_spam_trigger_view.php(21): XF\Template\Templater->escape(Object(XF\Phrase))
#7 src/XF/Template/Templater.php(1628): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array, NULL)
#8 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('log_spam_trigge...', Array)
#9 src/XF/Mvc/Renderer/Json.php(84): XF\Template\Template->render()
#10 src/XF/Mvc/Renderer/Json.php(68): XF\Mvc\Renderer\Json->renderHtmlFallback('XF:Log\\SpamTrig...', 'admin:log_spam_...', Array)
#11 src/XF/Mvc/Dispatcher.php(458): XF\Mvc\Renderer\Json->renderView('XF:Log\\SpamTrig...', 'admin:log_spam_...', Array)
#12 src/XF/Mvc/Dispatcher.php(440): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Json), Object(XF\Mvc\Reply\View))
#13 src/XF/Mvc/Dispatcher.php(400): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Json), Object(XF\Mvc\Reply\View))
#14 src/XF/Mvc/Dispatcher.php(58): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'json')
#15 src/XF/App.php(2337): XF\Mvc\Dispatcher->run()
#16 src/XF.php(488): XF\App->run()
#17 admin.php(13): XF::runApp('XF\\Admin\\App')
#18 {main}

The root cause for this seems to be two-fold:
  1. A contenttype contact does not exist (this can be seen on the screenshot, contact is printed as-as; it should be a phrase Contact) but is being used in XF\Service\Contact::checkForSpam()
    PHP:
    $checker = $this->app->spam()->contentChecker();
    $checker->check($user, $message, [
        'content_type' => 'contact'
    ]);
  2. It is possible to instantiate XF\Phrase with an empty name.
    When the phrase is being rendered, XF\Language:renderPhrase() is being called which in turn calls XF\Language::getEffectivePhraseName() that does access string offset 0.
    This offset does not exist if the phrase name is empty and causes the error.
Adressing either of these seems to fix this issue for me.
 
Last edited:

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.6).

Change log:
Fix missing content type for contact form and protect against a PHP 8.0 issue if a content type phrase is empty.
There may be a delay before changes are rolled out to the XenForo Community.
 
Top