symfony4 错误 spl_object_hash() 期望参数 1 为对象,给定的字符串

symfony4 error spl_object_hash() expects parameter 1 to be object, string given

当我尝试保留实体时出现错误:

        $newApplication = new NewApplication(
            $period,
            $ownFunds,
            $orderId,
            $additionalFields,
            $products,
            $rate,
            $latitude,
            $longitude,
            $personalDataSmsCode,
            $shopType,
            $shopUrl,
            $shopAddress,
            $cashierFullName,
            $merchantInn,
            $merchant,
            $shop,
            $customer,
            $cashier
        );

        $this->em->persist($newApplication);

实体构造函数代码:

/**
     * @param int                      $period
     * @param int                      $ownFunds
     * @param int                      $orderId
     * @param array | SaleCustomData[] $customData
     * @param array | UnsoldProduct[]  $products
     * @param Rate                     $rate
     * @param float                    $latitude
     * @param float                    $longitude
     * @param int                      $personalDataSmsCode
     * @param ShopType                 $shopType
     * @param string | null            $shopUrl
     * @param string | null            $shopAddress
     * @param string | null            $cashierFullName
     * @param Inn                      $merchantInn
     * @param Merchant                 $merchant
     * @param Shop                     $shop
     * @param Customer                 $customer
     * @param ShopCashier | null       $cashier
     */
    public function __construct(
        int $period,
        int $ownFunds,
        int $orderId,
        array $customData,
        array $products,
        Rate $rate,
        float $latitude,
        float $longitude,
        int $personalDataSmsCode,
        ShopType $shopType,
        ?string $shopUrl,
        ?string $shopAddress,
        string $cashierFullName,
        Inn $merchantInn,
        Merchant $merchant,
        Shop $shop,
        Customer $customer,
        ?ShopCashier $cashier = null
    ) {
        $this->merchantInn = $merchantInn;
        $this->shopType = $shopType;
        $this->period = $period;
        $this->ownFunds = $ownFunds;
        $this->orderId = $orderId;
        $this->customData = new ArrayCollection(array_unique($customData, SORT_REGULAR));
        $this->products = new ArrayCollection(array_unique($products, SORT_REGULAR));
        $this->rate = $rate;
        $this->latitude = $latitude;
        $this->longitude = $longitude;
        $this->personalDataSmsCode = $personalDataSmsCode;
        $this->shopUrl = $shopUrl;
        $this->shopAddress = $shopAddress;
        $this->cashierFullName = $cashierFullName;
        $this->merchant = $merchant;
        $this->shop = $shop;
        $this->cashier = $cashier;
        $this->customer = $customer;
    }

1) 首先为了解决这个问题我尝试了 dump NewApplication:

dump($newApplication);
die;

但这并没有帮助。 $newApplication 是对象 - 不是字符串,如错误所述。

2) 我的第二个版本是问题出在与 NewApplication 级联持续存在的对象中:

     * @param Rate                     $rate
     * @param ShopType                 $shopType
     * @param Inn                      $merchantInn
     * @param Merchant                 $merchant
     * @param Shop                     $shop
     * @param Customer                 $customer
     * @param ShopCashier | null       $cashier

但它们也是对象。这也不是我错误的原因。

还有什么解决办法?

问题出在包含集合的字段中:$customData$products。我放在那里的是字符串数组而不是对象数组。

处理大型实体时要小心!祝你好运!