symfony2 中 array_merge() 的错误

Error for array_merge() in symfony2

我真的遇到了一个大问题,因为当我在 app.php 环境中登录时,我收到了一个警告。顺便说一句,我正在使用 symfony2。

Warning: array_merge(): Argument #1 is not an array in C:\xampp\htdocs\Editracker\vendor\friendsofsymfony\user-bundle\Model\User.php line 181

这是穆User.php

 public function serialize()
{
    return serialize(array(
        $this->password,
        $this->salt,
        $this->usernameCanonical,
        $this->username,
        $this->expired,
        $this->locked,
        $this->credentialsExpired,
        $this->enabled,
        $this->id,
    ));
}

/**
 * Unserializes the user.
 *
 * @param string $serialized
 */
public function unserialize($serialized)
{
    $data1 = unserialize($serialized);
    // add a few extra elements in the array to ensure that we have enough keys when unserializing
    // older data which does not include all properties.
    $data = array_merge($data1, array_fill(0, 2, null));

    list(
        $this->password,
        $this->salt,
        $this->usernameCanonical,
        $this->username,
        $this->expired,
        $this->locked,
        $this->credentialsExpired,
        $this->enabled,
        $this->id
    ) = $data;
}

你能帮我解决这个问题吗?

像这样添加 is_array 条件:

public function serialize()
{
    return serialize(array(
        $this->password,
        $this->salt,
        $this->usernameCanonical,
        $this->username,
        $this->expired,
        $this->locked,
        $this->credentialsExpired,
        $this->enabled,
        $this->id,
    ));
}

/**
 * Unserializes the user.
 *
 * @param string $serialized
 */
public function unserialize($serialized)
{
    $data1 = unserialize($serialized);
    // add a few extra elements in the array to ensure that we have enough keys when unserializing
    // older data which does not include all properties.
    if (is_array($data1)) {
        $data = array_merge($data1, array_fill(0, 2, null));
    }

    list(
        $this->password,
        $this->salt,
        $this->usernameCanonical,
        $this->username,
        $this->expired,
        $this->locked,
        $this->credentialsExpired,
        $this->enabled,
        $this->id
    ) = $data;
}