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

Fixed Occasional "Array to string conversion" on saving preferences

Xon

Well-known member
#1
Every so often, I see an "Array to string conversion" when users are saving their preferences.

Code:
ErrorException: Array to string conversion - library/XenForo/Model/UserChangeLog.php:113 
Generated By: xxx, 22 minutes ago
#0 [internal function]: XenForo_Application::handlePhpError(8, 'Array to string...', '/var/www/sites/...', 113, Array)
#1 /var/www/sites/www/library/XenForo/Model/UserChangeLog.php(113): strval(Array)
#2 /var/www/sites/www/library/XenForo/Model/User.php(3108): XenForo_Model_UserChangeLog->logChanges(310668, Array, NULL)
#3 /var/www/sites/www/library/XenForo/DataWriter/User.php(1077): XenForo_Model_User->logChanges(310668, Array)
#4 /var/www/sites/www/library/SV/SubscriberRemoved/XenForo/DataWriter/User.php(6): XenForo_DataWriter_User->_postSave()
#5 /var/www/sites/www/library/XenForo/DataWriter.php(1409): SV_SubscriberRemoved_XenForo_DataWriter_User->_postSave()
#6 /var/www/sites/www/library/XenForo/ControllerPublic/Account.php(761): XenForo_DataWriter->save()
#7 /var/www/sites/www/library/XenForo/FrontController.php(347): XenForo_ControllerPublic_Account->actionPreferencesSave()
#8 /var/www/sites/www/library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#9 /var/www/sites/forums.spacebattles.com/html/index.php(13): XenForo_FrontController->run()
#10 {main}

array(4) {
  ["url"] => string(56) "https://forums.spacebattles.com/account/preferences-save"
  ["_GET"] => array(1) {
    ["/account/preferences-save"] => string(0) ""
  }
  ["_POST"] => array(16) {
    ["style_id"] => string(1) "5"
    ["language_id"] => string(1) "1"
    ["timezone"] => string(19) "America/Los_Angeles"
    ["default_watch_state"] => string(1) "1"
    ["enable_rte"] => string(1) "1"
    ["content_show_signature"] => string(1) "1"
    ["visible"] => string(1) "1"
    ["activity_visible"] => string(1) "1"
    ["enable_flash_uploader"] => string(1) "0"
    ["custom_fields"] => array(1) {
      ["userMargins"] => string(1) "1"
    }
    ["custom_fields_shown"] => array(4) {
      [0] => string(11) "userMargins"
      [1] => string(17) "disableResponsive"
      [2] => string(18) "disableQuoteExpand"
      [3] => string(14) "disableTwitter"
    }
    ["_xfToken"] => string(8) "********"
    ["save"] => string(12) "Save Changes"
    ["_xfRequestUri"] => string(75) "/"
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfResponseType"] => string(4) "json"
  }
}
Note; SV_SubscriberRemoved_XenForo_DataWriter_User doesn't do anything before the call to parent::_postSave()
 

Mike

XenForo developer
Staff member
#2
The only situation where I could see this happening relates to a custom field being changed from a non-array format to an array format or vice versa (I think). You can't directly change a custom field type, so this might be related to deleting and recreating a field with the same name. Can you think of whether this has happened? If so, rebuilding the user caches may resolve this.

I'm not seeing an obvious other cause.
 

imthebest

Formerly Super120
#3
My two cents: in one year of using XF since version 1.3 to 1.5 I have never seen the issue reported by Xon on my server error log.
 
Last edited:

Xon

Well-known member
#4
The only situation where I could see this happening relates to a custom field being changed from a non-array format to an array format or vice versa (I think). You can't directly change a custom field type, so this might be related to deleting and recreating a field with the same name. Can you think of whether this has happened? If so, rebuilding the user caches may resolve this.

I'm not seeing an obvious other cause.
As far as I'm aware, we haven't done a delete and recreate of a custom field with the same name. And if it has happened it was definitely not recently.

I'll try another user cache rebuild, but it has been done before recently to fix some other things before.
 

Moshe1010

Well-known member
#5
Not sure if it's connected but I receive something similar:

Code:
ErrorException: Array to string conversion - library/Zend/Db/Statement/Mysqli.php:208

Stack Trace
#0 [internal function]: XenForo_Application::handlePhpError(8, 'Array to string...', '/home/admin/pub...', 208, Array)
#1 /home/admin/public_html/library/Zend/Db/Statement/Mysqli.php(208): mysqli_stmt->execute()
#2 /home/admin/public_html/library/Zend/Db/Statement.php(317): Zend_Db_Statement_Mysqli->_execute(Array)
#3 /home/admin/public_html/library/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /home/admin/public_html/library/Zend/Db/Adapter/Abstract.php(632): Zend_Db_Adapter_Abstract->query('UPDATE `xf_user...', Array)
#5 /home/admin/public_html/library/Nobita/Sendy/XenForo/DataWriter/User.php(123): Zend_Db_Adapter_Abstract->update('xf_user_profile', Array, 'user_id = 6883')
#6 /home/admin/public_html/library/XenForo/DataWriter.php(1409): Nobita_Sendy_XenForo_DataWriter_User->_postSave()
#7 /home/admin/public_html/library/XenForo/ControllerAdmin/User.php(511): XenForo_DataWriter->save()
#8 /home/admin/public_html/library/ResetPasswordFromACP/ControllerAdmin/User.php(7): XenForo_ControllerAdmin_User->actionSave()
#9 /home/admin/public_html/library/XenForo/FrontController.php(347): ResetPasswordFromACP_ControllerAdmin_User->actionSave()
#10 /home/admin/public_html/library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#11 /home/admin/public_html/admin.php(13): XenForo_FrontController->run()
#12 {main}

Request State
array(3) {
["url"] => string(47) "https://www.website.co.il/admin.php?users/6883/save"
["_GET"] => array(1) {
["users/6883/save"] => string(0) ""
}
["_POST"] => array(46) {
["username"] => string(8) "liortest"
["email"] => string(18) "fafsssaf@gaaga.com"
["password"] => string(8) "********"
["user_group_id"] => string(1) "2"
["secondary_group_ids"] => array(1) {
[0] => string(2) "24"
}
["user_state"] => string(5) "valid"
["gender"] => string(0) ""
["dob_month"] => string(0) ""
["dob_day"] => string(0) ""
["dob_year"] => string(0) ""
["location"] => string(0) ""
["occupation"] => string(0) ""
["homepage"] => string(0) ""
["custom_fields"] => array(8) {
["gvbh"] => string(0) ""
["mshql"] => string(0) ""
["akhvz_shvmn"] => string(0) ""
["khdr_kvshr"] => string(0) ""
["skype"] => string(0) ""
["gtalk"] => string(0) ""
["facebook"] => string(0) ""
["twitter"] => string(0) ""
}
["custom_fields_shown"] => array(8) {
[0] => string(4) "gvbh"
[1] => string(5) "mshql"
[2] => string(11) "akhvz_shvmn"
[3] => string(10) "khdr_kvshr"
[4] => string(5) "skype"
[5] => string(5) "gtalk"
[6] => string(8) "facebook"
[7] => string(7) "twitter"
}
["about"] => string(0) ""
["custom_title"] => string(0) ""
["signature"] => string(0) ""
["message_count"] => string(2) "90"
["like_count"] => string(1) "0"
["trophy_points"] => string(1) "0"
["reputation"] => string(1) "6"
["user_edit_form"] => string(1) "1"
["style_id"] => string(1) "0"
["language_id"] => string(1) "2"
["timezone"] => string(13) "Europe/Athens"
["enable_rte"] => string(1) "1"
["enable_flash_uploader"] => string(1) "1"
["content_show_signature"] => string(1) "1"
["email_on_conversation"] => string(1) "1"
["default_watch_state"] => string(14) "watch_no_email"
["visible"] => string(1) "1"
["activity_visible"] => string(1) "1"
["receive_admin_email"] => string(1) "1"
["allow_view_profile_enable"] => string(1) "1"
["allow_view_profile"] => string(8) "everyone"
["allow_receive_news_feed_enable"] => string(1) "1"
["allow_receive_news_feed"] => string(8) "everyone"
["allow_send_personal_conversation_enable"] => string(1) "1"
["allow_send_personal_conversation"] => string(7) "members"
["allow_view_identities_enable"] => string(1) "1"
["allow_view_identities"] => string(8) "everyone"
["_xfToken"] => string(8) "********"
["_xfRequestUri"] => string(26) "/admin.php?users/6883/edit"
["_xfNoRedirect"] => string(1) "1"
["_xfResponseType"] => string(4) "json"
}
}
 

Chris D

XenForo developer
Staff member
#6
I'm not 100% sure, but it looks like that particular error might be related to the Sendy add-on.

If the fault is reproducible, please try with that add-on disabled (and the others that are mentioned) to see if the issue persists.
 
Last edited:

Moshe1010

Well-known member
#7
I'm not 100% sure, but it looks like that particular error might be related to the Sendy add-on.

If the fault is reproducible, please try with that add-on disabled (and the others that are mentioned) to see if the issue persists.
Yeah I've contacted @Nobita.Kun first, but he thinks it maybe related to this issue.
 

Chris D

XenForo developer
Staff member
#8
It could be. But the first step is to disable that add-on and try again. If the problem persists then it could be related to this.
 

Mike

XenForo developer
Staff member
#9
@Xon, is there a frequency this happens with? If you go to edit the user in the ACP, does it trigger the same thing?

I'd be looking for a way that we could get a little bit of extra debugging info in there so we could try to figure out what's specifically causing it, rather than guessing. I suspect it's this code:
Code:
                        if (is_array($oldValue) && is_array($newValue))
                        {
                            $changes["$field:$customField"] = array(serialize($oldValue), serialize($newValue));
                        }
                        else
                        {
                            $changes["$field:$customField"] = array($oldValue, $newValue);
                        }
Where one of the values is an array but the other isn't, so it's falling through to the else case.
 

Xon

Well-known member
#10
@Mike Triggering this is challenging. Saving via the AdminCP doesn't do anything.

This is the change log on the user's account:

Capture.PNG


Here is the configuration of that custom field:
custom_field1.png
custom_field2.png
custom_field3.png
 

Mike

XenForo developer
Staff member
#11
I have managed to reproduce this the way I proposed initially: I made a radio field (with on/off options), set a value for that in my profile, deleted the field, and then recreated the field as a checkbox (with a single on option, like the screenshot). This triggered a situation where the old value was a string and the new value was an array (in the field cache). I've added code to try to handle this case. I have to assume this is how it happened here as I can't see another way it could be triggered.

I'm going to consider this fixed for 1.5.1, but let me know if it comes back.