我要将User
模型(对象)分配给我的一个stdClass属性,这是我的stdclass通过DB获取作为查询结果:
{#803 ▼
+"user": 84
+"id_list": "7,1"
+"total": "125002.00"
+"settlement_id": null
+"bank_code": null
+"gateway_id": null
+"settlement_date": null
}
如果我尝试将User
模型分配给user
属性,则抛出异常:
类App \ User的对象无法转换为int
这是我尝试将用户模型分配给stdclass
的方式// $settlements is an array containing stdClasses
// $user_list is an array containing User models
foreach($settlements as $settlement){
foreach($user_list as $user){
if($settlement->user == $user->id){
$settlement->user = $user;
}
}
}
答案 0 :(得分:0)
很可能你的$settlement->user
是一个对象,PHP试图将其转换为整数,同时在以下行中进行比较:
if($settlement->user == $user->id){
在执行比较之前,您需要确保它不是已经分配的对象,例如:
if (!is_object($settlement->user) && $settlement->user == $user->id)
或
if (!$settlement->user instanceof User && $settlement->user == $user->id)
(假设$user
是User
类的实例;将其更改为实际的任何内容)
答案 1 :(得分:0)
找到它,删除以下行:
template <unsigned int blockSize>
__global__ void parreduc(float *array_in, float *reduct, size_t array_len)
{
extern volatile __shared__ float sdata[];
size_t tid = threadIdx.x,
gridSize = blockSize * gridDim.x,
i = blockIdx.x * blockSize + tid;
sdata[tid] = 0;
while (i < array_len)
{ sdata[tid] += array_in[i];
i += gridSize; }
__syncthreads();
if (blockSize >= 512)
{ if (tid < 256) sdata[tid] += sdata[tid + 256]; __syncthreads(); }
if (blockSize >= 256)
{ if (tid < 128) sdata[tid] += sdata[tid + 128]; __syncthreads(); }
if (blockSize >= 128)
{ if (tid < 64) sdata[tid] += sdata[tid + 64]; __syncthreads(); }
if (tid < 32)
{ if (blockSize >= 64) sdata[tid] += sdata[tid + 32];
if (blockSize >= 32) sdata[tid] += sdata[tid + 16];
if (blockSize >= 16) sdata[tid] += sdata[tid + 8];
if (blockSize >= 8) sdata[tid] += sdata[tid + 4];
if (blockSize >= 4) sdata[tid] += sdata[tid + 2];
if (blockSize >= 2) sdata[tid] += sdata[tid + 1]; }
if (tid == 0) reduct[blockIdx.x] = sdata[0];
}