get_class()期望参数1是object,使用bitly-url-shortener时给出的字符串

时间:2015-06-05 09:18:51

标签: php html yii

我想使用bitly-url-shortener(http://www.yiiframework.com/extension/bitly-url-shortener/)来缩短我的网址。我正在使用的代码如下,

<?php Yii::app()->bitly->shorten('http://www.betaworks.com')->getResponseData(); ?>

它给了我这个错误,

 get_class() expects parameter 1 to be object, string given

D:\_App\buddyshop\protected\extensions\bitly\VGBitly.php(578)

566      */
567     public function getErrorMessage()
568     {
569         return $this->errorMessage;
570     }
571     
572     /**
573      * @return array - Convert a SimpleXML object to an array so we
574      * Could safely store it in the cache and retrieve it when needed.
575      */
576     protected function simplexml2array($xml) 
577     {
578         if (get_class($xml) == 'SimpleXMLElement') 
579         {
580             $attributes = $xml->attributes();
581             foreach($attributes as $k=>$v) 
582             {
583                 if ($v) $a[$k] = (string) $v;
584             }
585             $x = $xml;
586             $xml = get_object_vars($xml);
587         }
588         if (is_array($xml)) 
589         {
590             if (count($xml) == 0) return (string) $x; // for CDATA

错误显示在第578行。

非常感谢任何帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

由于您已经联系了代码作者,希望您能从他们那里获得更好的解决方案,但同时您可以在下方使其工作:

替换:

if (get_class($xml) == 'SimpleXMLElement') 

if (is_object($xml) && get_class($xml) == 'SimpleXMLElement')