From 29ccde9bb32a6f220635014373006e53145cc98d Mon Sep 17 00:00:00 2001 From: Eli De-Mayo Date: Wed, 3 Feb 2016 13:49:43 +0200 Subject: [PATCH 1/2] Array key references break argument processing To prevent encountering the "Array key references break argument processing" (https://bugs.php.net/bug.php?id=70993) bug on PHP 7.0.1 Replaced all array key references. --- soapclient/SforceEnterpriseClient.php | 42 ++++++++++++--------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/soapclient/SforceEnterpriseClient.php b/soapclient/SforceEnterpriseClient.php index 3aaa976..acc5702 100644 --- a/soapclient/SforceEnterpriseClient.php +++ b/soapclient/SforceEnterpriseClient.php @@ -25,7 +25,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ require_once ('SforceBaseClient.php'); - /** * This file contains two classes. * @package SalesforceSoapClient @@ -37,11 +36,9 @@ */ class SforceEnterpriseClient extends SforceBaseClient { const ENTERPRISE_NAMESPACE = 'urn:enterprise.soap.sforce.com'; - function SforceEnterpriseClient() { $this->namespace = self::ENTERPRISE_NAMESPACE; } - /** * Adds one or more new individual objects to your organization's data. * @param array $sObjects Array of one or more sObjects (up to 200) to create. @@ -50,7 +47,8 @@ function SforceEnterpriseClient() { * @return SaveResult */ public function create($sObjects, $type) { - foreach ($sObjects as &$sObject) { + $arg = []; + foreach ($sObjects as $sObject) { // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) $xmlStr = ''; if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) { @@ -60,19 +58,16 @@ public function create($sObjects, $type) { } // ------ - $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); - + $soapObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2) if($xmlStr != '') { - $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); + $soapObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); } // ------ + $arg[] = $soapObject; } - $arg = $sObjects; - return parent::_create(new SoapParam($arg, "sObjects")); } - /** * Updates one or more new individual objects to your organization's data. * @param array sObjects Array of sObjects @@ -81,9 +76,9 @@ public function create($sObjects, $type) { * @return UpdateResult */ public function update($sObjects, $type, $assignment_header = NULL, $mru_header = NULL) { - - foreach ($sObjects as &$sObject) { - + $arg = new stdClass; + $arg->sObjects = []; + foreach ($sObjects as $sObject) { // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) $xmlStr = ''; if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) { @@ -93,19 +88,18 @@ public function update($sObjects, $type, $assignment_header = NULL, $mru_header } // ------ - $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); + $soapObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2) if($xmlStr != '') { - $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); + $soapObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); } // ------ + $arg->sObjects[] = $soapObject; } - $arg = new stdClass; - $arg->sObjects = $sObjects; + return parent::_update($arg); } - /** * Creates new objects and updates existing objects; uses a custom field to * determine the presence of existing objects. In most cases, we recommend @@ -119,8 +113,9 @@ public function update($sObjects, $type, $assignment_header = NULL, $mru_header */ public function upsert($ext_Id, $sObjects, $type = 'Contact') { $arg = new stdClass; + $arg->sObjects = []; $arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); - foreach ($sObjects as &$sObject) { + foreach ($sObjects as $sObject) { // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) $xmlStr = ''; if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) { @@ -130,18 +125,17 @@ public function upsert($ext_Id, $sObjects, $type = 'Contact') { } // ------ - $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); - + $soapObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2) if($xmlStr != '') { - $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); + $soapObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); } // ------ + $arg->sObjects[] = $soapObject; } - $arg->sObjects = $sObjects; + return parent::_upsert($arg); } - /** * Merge records * From d6f105c098eaab001ad1d11522d3dccbe225b6ba Mon Sep 17 00:00:00 2001 From: Marijn Koesen Date: Fri, 11 Mar 2016 09:41:58 +0100 Subject: [PATCH 2/2] Replaced the deprecated constructor with __construct() --- soapclient/SforceEnterpriseClient.php | 2 +- soapclient/SforcePartnerClient.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/soapclient/SforceEnterpriseClient.php b/soapclient/SforceEnterpriseClient.php index acc5702..b018efc 100644 --- a/soapclient/SforceEnterpriseClient.php +++ b/soapclient/SforceEnterpriseClient.php @@ -36,7 +36,7 @@ */ class SforceEnterpriseClient extends SforceBaseClient { const ENTERPRISE_NAMESPACE = 'urn:enterprise.soap.sforce.com'; - function SforceEnterpriseClient() { + public function __construct() { $this->namespace = self::ENTERPRISE_NAMESPACE; } /** diff --git a/soapclient/SforcePartnerClient.php b/soapclient/SforcePartnerClient.php index 66bb75a..38c30e8 100644 --- a/soapclient/SforcePartnerClient.php +++ b/soapclient/SforcePartnerClient.php @@ -74,7 +74,7 @@ function __doRequest($request, $location, $action, $version, $one_way=0) { class SforcePartnerClient extends SforceBaseClient { const PARTNER_NAMESPACE = 'urn:partner.soap.sforce.com'; - function SforcePartnerClient() { + public function __construct() { $this->namespace = self::PARTNER_NAMESPACE; } @@ -223,4 +223,4 @@ private function _retrieveResult($response) { return $arr; } -} \ No newline at end of file +}