繁体   English   中英

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

[英]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)首先要解决这个问题,我尝试转储NewApplication:

dump($newApplication);
die;

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

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

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

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

还有什么可以解决的?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM