修复PayPal PHP SDK核心中的错误

修复PayPal PHP SDK核心中的错误,php,paypal,Php,Paypal,我在github上找到的merchant sdk php在解决问题时遇到了问题。出于某种原因,它抛出了这个错误。我试着查看代码,但我不理解它,也看不出问题所在 致命错误:在第89行的/home/content/08/10639508/html/wp content/plugins/generation manager/library/vendor/paypal/paypal-sdk-core-php-bc7822a/lib/PPXmlMessage.php中调用未定义的方法stdClass::t

我在github上找到的merchant sdk php在解决问题时遇到了问题。出于某种原因,它抛出了这个错误。我试着查看代码,但我不理解它,也看不出问题所在

致命错误:在第89行的/home/content/08/10639508/html/wp content/plugins/generation manager/library/vendor/paypal/paypal-sdk-core-php-bc7822a/lib/PPXmlMessage.php中调用未定义的方法stdClass::toXMLString()

    <?php
toXMLString();
}
/**
*@返回字符串
*/
公共函数toXMLString()
{
如果(count($properties=get\u object\u vars($this))>=2&&array\u key\u存在($value',$properties)){
$attributes=array();
foreach(数组_键($properties)作为$property){
如果($property=='value')继续;
if($annots=PPUtils::propertyAnnotations($this,$property))&&isset($annots['attribute'])){
if($propertyValue=$this->{$property})==NULL | |$propertyValue==NULL){
$attributes[]=NULL;
继续;
}
$attributes[]=$property.'='.PPUtils::escapeInvalidXmlCharsRegex($propertyValue)。'';
}
}
如果(计数($attributes)){
返回内爆(“”,$attributes)。“>”.PPUtils::escapeInvalidXmlCharsRegex($this->value);
}
}
$xml=array();
foreach($properties as$property=>$defaultValue){
if($propertyValue=$this->{$property})==NULL | |$propertyValue==NULL){
继续;
}
if(is_数组($defaultValue)| is_数组($propertyValue)){
foreach($propertyValue作为$item){
如果(!是_对象($item)){
$xml[]=$this->buildProperty($property,$item);
}否则{
$xml[]=$this->buildProperty($property,$item);
}
}
}否则{
$xml[]=$this->buildProperty($property,$propertyValue);
}
}
返回内爆($xml);
}
/**
*@param string$property
*@param PPXmlMessage |字符串$value
*@param string$命名空间
*@返回字符串
*/
私有函数buildProperty($property,$value,$namespace='ebl')
{
$annotations=PPUtils::propertyAnnotations($this,$property);
如果(!empty($annotations['namespace'])){
$namespace=$annotations['namespace'];
}
如果(!empty($annotations['name'])){
$property=$annotations['name'];
}
$el=''.PPUtils::escapeInvalidXmlCharsRegex($value);
}否则{
如果(substr($value=$value->toXMLString(),0,1)==''。$value;
}否则{
$el.=''.$value;
}
}
返回$el.';
}
/**
*@param数组$map
*@param字符串$prefix
*/
公共函数init(数组$map=array(),$prefix='')
{
if(空($map)){
返回;
}
如果($first=reset($map))&&!是数组($first)&&!是数字(键($map))){
父::init($map,$prefix);
返回;
}
$propertiesMap=PPUtils::objectProperties($this);
$arrayCtr=array();
foreach($map as$element){
if(空($element)| |空($element['name'])){
继续;
}elseif(!array\u key\u exists($property=strtolower($element['name']),$propertiesMap)){
如果(!preg_match('~^(+)[\[\(](\d+[\]\)]$~',$property,$m)){
继续;
}
$element['name']=$m[1];
$element['num']=$m[2];
}
$element['name']=$propertiesMap[strtolower($element['name']);
if(PPUtils::isPropertyArray($this$element['name']){
$arrayCtr[$element['name']]=isset($arrayCtr[$element['name']])?($arrayCtr[$element['name']]]+1):0;
$element['num']=$arrayCtr[$element['name']];
} 
if(!empty($element[“attributes”])&&is_数组($element[“attributes”])){
foreach($element[“attributes”]作为$key=>$val){
$element[“子项”][]=数组(
'name'=>$key,
“text”=>$val,
);
}
if(isset($element['text'])){
$element[“子项”][]=数组(
“名称”=>“值”,
'text'=>$element['text'],
);
}
$this->fillRelation($element['name'],$element);
}elseif(!empty($element['text'])){
$this->{$element['name']}=$element['text'];
}elseif(!empty($element[“children”])和&is_数组($element[“children”])){
$this->fillRelation($element['name'],$element);
}
}       
}
/**
*@param string$property
*@param数组$element
*/
私有函数fillRelation($property,array$element)
{
如果(!class_存在($type=PPUtils::propertyType($this,$property))){
触发错误(“未找到类$type.”,E_用户通知);
return;//忽略
}
if(isset($element['num']){//对象数组
$this->{$property}[$element['num']]=$item=new$type();
$item->init($element['children']);
}否则{
$this->{$property}=new$type();
$this->{$property}->init($element[“children”]);
}
}

}

也许你在PaymentDetail记录上使用了json\u编码/解码?似乎PayPal对组件类非常挑剔;stdClass(json\u解码生成)不会剪切它。Serialize可以工作,但使用它时会有警告。

我也有同样的错误(对于我的实时应用程序,它在我的测试代码中运行良好)。我最终意识到,当我将测试代码复制到实时环境中,并将我的凭据和URL从沙盒更改为实时凭据和URL时……我在调用SetExpressCheckout之前不知何故删除了初始化PaymentDetailsType对象的一行代码。因此,这个错误似乎与此无关,但它
/**
 * @return string
 */
public function toSOAP()
{
    return $this->toXMLString();
}



/**
 * @return string
 */
public function toXMLString()
{
    if (count($properties = get_object_vars($this)) >= 2 && array_key_exists('value', $properties)) {
        $attributes = array();
        foreach (array_keys($properties) as $property) {
            if ($property === 'value') continue;
            if (($annots = PPUtils::propertyAnnotations($this, $property)) && isset($annots['attribute'])) {
                if (($propertyValue = $this->{$property}) === NULL || $propertyValue == NULL) {
                    $attributes[] = NULL;
                    continue;
                }

                $attributes[] = $property . '="' . PPUtils::escapeInvalidXmlCharsRegex($propertyValue) . '"';
            }
        }

        if (count($attributes)) {
            return implode(' ', $attributes) . '>' . PPUtils::escapeInvalidXmlCharsRegex($this->value);
        }
    }

    $xml = array();
    foreach ($properties as $property => $defaultValue) {
        if (($propertyValue = $this->{$property}) === NULL || $propertyValue == NULL) {
            continue;
        }

        if (is_array($defaultValue) || is_array($propertyValue)) {
            foreach ($propertyValue as $item) {
                if (!is_object($item)) {
                    $xml[] = $this->buildProperty($property, $item);
                }else{
                    $xml[] = $this->buildProperty($property, $item);
                }
            }

        } else {
            $xml[] = $this->buildProperty($property, $propertyValue);
        }
    }

    return implode($xml);
}



/**
 * @param string $property
 * @param PPXmlMessage|string $value
 * @param string $namespace
 * @return string
 */
private function buildProperty($property, $value, $namespace = 'ebl')
{
    $annotations = PPUtils::propertyAnnotations($this, $property);
    if (!empty($annotations['namespace'])) {
        $namespace = $annotations['namespace'];
    }
    if (!empty($annotations['name'])) {
        $property = $annotations['name'];
    }

    $el = '<' . $namespace . ':' . $property;
    if (!is_object($value)) {
        $el .= '>' . PPUtils::escapeInvalidXmlCharsRegex($value);

    } else {
        if (substr($value = $value->toXMLString(), 0, 1) === '<' || $value=='') {
            $el .= '>' . $value;

        } else {
            $el .= ' ' . $value;
        }
    }

    return $el . '</' . $namespace . ':' . $property . '>';
}



/**
 * @param array $map
 * @param string $prefix
 */
public function init(array $map = array(), $prefix = '')
{
    if (empty($map)) {
        return;
    }

    if (($first = reset($map)) && !is_array($first) && !is_numeric(key($map))) {
        parent::init($map, $prefix);
        return;
    }

    $propertiesMap = PPUtils::objectProperties($this);
    $arrayCtr = array();        
    foreach ($map as $element) {

        if (empty($element) || empty($element['name'])) {
            continue;

        } elseif (!array_key_exists($property = strtolower($element['name']), $propertiesMap)) {
            if (!preg_match('~^(.+)[\[\(](\d+)[\]\)]$~', $property, $m)) {
                continue;
            }

            $element['name'] = $m[1];
            $element['num'] = $m[2];
        }
        $element['name'] = $propertiesMap[strtolower($element['name'])];
        if(PPUtils::isPropertyArray($this, $element['name'])) {             
            $arrayCtr[$element['name']] = isset($arrayCtr[$element['name']]) ? ($arrayCtr[$element['name']]+1) : 0;             
            $element['num'] = $arrayCtr[$element['name']];
        } 
        if (!empty($element["attributes"]) && is_array($element["attributes"])) {
            foreach ($element["attributes"] as $key => $val) {
                $element["children"][] = array(
                    'name' => $key,
                    'text' => $val,
                );
            }

            if (isset($element['text'])) {
                $element["children"][] = array(
                    'name' => 'value',
                    'text' => $element['text'],
                );
            }

            $this->fillRelation($element['name'], $element);

        } elseif (!empty($element['text'])) {
            $this->{$element['name']} = $element['text'];

        } elseif (!empty($element["children"]) && is_array($element["children"])) {
            $this->fillRelation($element['name'], $element);
        }
    }       
}



/**
 * @param string $property
 * @param array $element
 */
private function fillRelation($property, array $element)
{
    if (!class_exists($type = PPUtils::propertyType($this, $property))) {
        trigger_error("Class $type not found.", E_USER_NOTICE);
        return; // just ignore
    }

    if (isset($element['num'])) { // array of objects
        $this->{$property}[$element['num']] = $item = new $type();
        $item->init($element['children']);

    } else {
        $this->{$property} = new $type();
        $this->{$property}->init($element["children"]);
    }
}