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

问题描述 投票:0回答:1

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

        $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)首先要解决此问题,我尝试转储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

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

还有什么解决方案?

php doctrine-orm symfony4 entitymanager persist
1个回答
0
投票

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

与大型实体合作时要小心!祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.