New entity default values do not match type hints resulting in common "Argument #n ($string) must be of type string, null given" errors

Xon

Well-known member
Affected version
2.3.2
XF\Criteria\UserCriteria::_matchEmailSearch fails for guest users

Code:
TypeError: XF\Util\Str::strtolower(): Argument #1 ($string) must be of type string, null given, called in /var/www/html/src/XF/Criteria/AbstractCriteria.php on line 206 src\XF\Util\Str.php:210
Generated by: Unknown account Aug 17, 2024 at 9:11 PM

Code:
Stack trace
#0 src\XF\Criteria\AbstractCriteria.php(206): XF\Util\Str::strtolower(NULL)
#1 src\XF\Criteria\UserCriteria.php(101): XF\Criteria\AbstractCriteria->findNeedle('rr.com,roadrunn...', NULL)
#2 src\XF\Criteria\AbstractCriteria.php(67): XF\Criteria\UserCriteria->_matchEmailSearch(Array, Object(XF\Entity\User))
#3 src\XF\NoticeList.php(99): XF\Criteria\AbstractCriteria->isMatched(Object(XF\Entity\User))
#4 src\XF\Pub\App.php(658): XF\NoticeList->addConditionalNotice(80, 'scrolling', '<p>@RoadRunner ...', Array)
#5 src\XF\Pub\App.php(593): XF\Pub\App->getNoticeList(Array)
#6 src\XF\App.php(2560): XF\Pub\App->renderPageHtml('<div class="blo...', Array, Object(XF\Mvc\Reply\Message), Object(XF\Mvc\Renderer\Html))
#7 src\XF\Mvc\Dispatcher.php(414): XF\App->renderPage('<div class="blo...', Object(XF\Mvc\Reply\Message), Object(XF\Mvc\Renderer\Html))
#8 src\XF\Mvc\Dispatcher.php(66): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\Message), 'html')
#9 src\XF\App.php(2813): XF\Mvc\Dispatcher->run()
#10 src\XF.php(802): XF\App->run()
#11 index.php(23): XF::runApp('XF\\Pub\\App')
#12 {main}

This comes from $user->email being null:
PHP:
protected function _matchEmailSearch(array $data, User $user)
{
    if ($this->findNeedle($data['needles'], $user->email) === false)
    {
        return false;
    }
    else
    {
        return true;
    }
}

But the actual root causes is, the type hint is saying string not string | null and thus for guest users is created with a value of null

PHP:
public static function getStructure(Structure $structure)
{
    $structure->table = 'xf_user';
...
    'email' => ['type' => self::STR, 'maxLength' => 120],
There is no default = '' stanza, so it defaults to null. This is actually a flaw in the property type hinting from xf-dev:entity-class-properties. It only inspects nullable and type flags, and should add the | null to the type definition if there is no default value.

Alternatively, new entities should have a default value for columns initialized if they aren't set tot nullable. (ie empty string, 0 or whatever)
 
I'm trying to upgrade my forum to 2.3.2 and think I am I'm getting this error even with my add-ons disabled.

Code:
Server error log
TypeError: XF\Util\Str::strtolower(): Argument #1 ($string) must be of type string, null given, called in D:\cuswebs\www1\forums.*****.com\src\XF\Criteria\AbstractCriteria.php on line 206 src\XF\Util\Str.php:210
Generated by: Unknown account Aug 18, 2024 at 11:52 PM
Stack trace
#0 src\XF\Criteria\AbstractCriteria.php(206): XF\Util\Str::strtolower(NULL)
#1 src\XF\Criteria\UserCriteria.php(101): XF\Criteria\AbstractCriteria->findNeedle('rr.com,roadrunn...', NULL)
#2 src\XF\Criteria\AbstractCriteria.php(67): XF\Criteria\UserCriteria->_matchEmailSearch(Array, Object(XF\Entity\User))
#3 src\XF\NoticeList.php(99): XF\Criteria\AbstractCriteria->isMatched(Object(XF\Entity\User))
#4 src\XF\Pub\App.php(658): XF\NoticeList->addConditionalNotice(80, 'scrolling', '<p>@RoadRunner ...', Array)
#5 src\XF\Pub\App.php(593): XF\Pub\App->getNoticeList(Array)
#6 src\XF\App.php(2560): XF\Pub\App->renderPageHtml('<div class="blo...', Array, Object(XF\Mvc\Reply\Message), Object(XF\Mvc\Renderer\Html))
#7 src\XF\Mvc\Dispatcher.php(414): XF\App->renderPage('<div class="blo...', Object(XF\Mvc\Reply\Message), Object(XF\Mvc\Renderer\Html))
#8 src\XF\Mvc\Dispatcher.php(66): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\Message), 'html')
#9 src\XF\App.php(2813): XF\Mvc\Dispatcher->run()
#10 src\XF.php(802): XF\App->run()
#11 index.php(23): XF::runApp('XF\\Pub\\App')
#12 {main}
Request state
array(4) {
  ["url"] => string(51) "/forums/2002-2005/page-184"
  ["referrer"] => bool(false)
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}
 
It is a bug with using a user criterial which matches on emails which runs against guest users. Tick the "User is logged in" checkbox, and it'll skip the broken guest user setup.
 
It is a bug with using a user criterial which matches on emails which runs against guest users. Tick the "User is logged in" checkbox, and it'll skip the broken guest user setup.
@Xon Where is the "user is logged" in checkbox setting you are referring to?

Is there some temporary code I could edit until XF released a fix/update?

Thank you! This is the only thing keeping me from launching 2.3 on our forum.

The website will not load for guests at all until this is resolved.
 
Last edited:
@Xon or @Paul Where is the "user is logged" in checkbox setting you are referring to?

Is there some temporary code I could edit until XF released a fix/update?

Thank you! This is the only thing keeping me from launching 2.3 on our forum.

The website will not load for guests at all until this is resolved.
Nothing to do with me... Maybe you meant @Paul B (y)
 
Back
Top Bottom