【问题标题】:symfony4 error spl_object_hash() expects parameter 1 to be object, string givensymfony4 错误 spl_object_hash() 期望参数 1 是对象,给定字符串
【发布时间】:2019-10-21 14:22:14
【问题描述】:

尝试持久化实体时出现错误:

        $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】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-10-09
      • 1970-01-01
      • 2021-02-13
      • 1970-01-01
      • 2015-06-27
      • 1970-01-01
      • 2020-11-22
      • 2018-08-07
      • 2017-08-30
      相关资源
      最近更新 更多