SOAP-ERROR: object has no 'quantity' property问题排查求助
解决SOAP-ERROR: Encoding: object has no 'quantity' property问题
这个错误的核心原因是你传递给SOAP方法的参数结构完全不符合接口要求,和你删不删quantity代码段无关——接口要求这个字段必须存在于正确的层级结构里,而你的写法把所有参数拆成了多个独立数组,导致SOAP解析器找不到它。
问题出在哪?
看你调用InventoryReceipt的代码:
$Response = $SOAP->InventoryReceipt( array('item' => array('idx' => "$IDX")), array('ean' => "$Barcode"), array('workOrderPrefix' => "LS0001"), array('workOrderSuffix' => "000"), array('quantity' => "$Quantity"), array('adeptKey' => "XXXX1"), array('creationDate' => "$Date"), array('to' => "0"), array('note' => "Wykonał: $UserLogin - $Datetime"), array('documentType' => "PR") );
你给InventoryReceipt传了10个独立的数组参数,但SOAP接口的InventoryReceipt方法几乎肯定是期望一个包含所有字段的单一结构化数组/对象。比如,ean、quantity这些字段应该是item对象的子属性,而adeptKey、creationDate是顶层参数。
正确的写法
你需要把所有参数按照接口定义的层级结构整合到一个数组里,再传给方法。假设接口的参数结构是:InventoryReceipt接收一个包含item、adeptKey、creationDate等字段的对象,其中item又包含idx、ean、quantity等子字段,修改后的代码应该是这样:
while($Data = pg_fetch_row($GetData)){ $ID = $Data[0]; $ID_C = $Data[1]; $UserLogin = $Data[2]; $Barcode = $Data[3]; $Quantity = $Data[4]; $ADate = $Data[5]; $Date = date('Y-m-d', strtotime($ADate)); $Datetime = date('Y-m-d H:i', strtotime($ADate)); try{ $SOAP = new SoapClient($TrawersAddress); // 构造符合接口要求的结构化参数 $requestParams = [ 'item' => [ 'idx' => $IDX, 'ean' => $Barcode, 'workOrderPrefix' => "LS0001", 'workOrderSuffix' => "000", 'quantity' => $Quantity // 这里把quantity放到item的子属性里 ], 'adeptKey' => "XXXX1", 'creationDate' => $Date, 'to' => "0", 'note' => "Wykonał: $UserLogin - $Datetime", 'documentType' => "PR" ]; $Response = $SOAP->InventoryReceipt($requestParams); } catch(Exception $e){ echo $e->getMessage(); } $IDX++; }
额外建议:确认接口的参数结构
如果不确定接口的具体结构,可以通过SoapClient的内置方法查看:
$SOAP = new SoapClient($TrawersAddress); // 打印所有可用方法 print_r($SOAP->__getFunctions()); // 打印所有数据类型定义 print_r($SOAP->__getTypes());
这会输出接口的方法签名和参数结构,你可以根据输出调整$requestParams的结构,确保完全匹配。
内容的提问来源于stack exchange,提问作者MateoSkyline
相关产品推荐
相关产品推荐

