Symfony4错误spl_object_hash()期望参数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(首先要解决此问题,我尝试转储新应用程序:

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。我放了字符串数组而不是对象数组。

使用大型实体时要小心!祝你好运!

相关内容

  • 没有找到相关文章

最新更新